Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Play/Pause like a media button on Keyboard

Status
Not open for further replies.

Turpis

Programmer
Apr 16, 2002
151
0
0
How can I Play/Pause the same way my Logitech keyboard media button "play/pause" does? I need this for an application. And not the my.computer.audio or the mci junk, that is for .wav. I need to pause whatever device might be actively playing music or movies just like the keyboard button does.

Charles
Quality Assurance/Developer
 
Turpis,

Not sure if this is what you are looking for.
e.KeyCode = Windows.Forms.Keys.MediaPlayPause

Ernst Jan
 
ErnstJan,
Didn't work, this is a console application. What I tried is this

Imports System.Windows

Code:
Windows.Forms.SendKeys.SendWait(Windows.Forms.Keys.MediaPlayPause)

No luck. However, since the program is specifically for me (and maybe some of the other IT department), I exclusively use iTunes and I just targeted that application for now. With:

Code:
Imports iTunesLib

    Private Const iTunesProcessName As String = "iTunes"

    Sub Main()
        StopMyMusic_iTunes()
    End Sub

    Private Sub StopMyMusic_iTunes()
        If IsAppRunning(iTunesProcessName) Then
            Dim iTunes As New iTunesApp
            If iTunes.PlayerState = ITPlayerState.ITPlayerStatePlaying Then
                iTunes.Pause()
            End If
        End If
    End Sub

    Private Function IsAppRunning(ByVal name As String) As Boolean
        Dim appProcList() As Process
        Dim appProc As Process

        appProcList = Process.GetProcesses()

        For Each appProc In appProcList
            If appProc.ProcessName = name Then
                Return True
                Exit Function
            End If
        Next

        Return False
    End Function

Thanks anyway. Beginning to suspect from my searching on the internet that there isn't a windows "global" play/pause and that keyboards applications must be doing what I am doing and checking to see if a known music/dvd application is running and if so then play/pausing it specifically. The difference is that they are checking for them all.

Charles
Quality Assurance/Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top