0

I know that pause/play key(from keyboard)'s keyCode is 179, but how can I programically press those multimedia keys from VB6? There are some questions about it but they're for C#/C++/VB.Net

1 Answers1

3

You can use the Chr function to convert your keycode to a string that SendKeys can use:

SendKeys Chr(179)

You might run into a Permission Denied error next, which you can work around by using a WScript.Shell object by using this subroutine:

Private Sub SendKeysViaWshShell(p_iKeyCode As Integer, Optional p_fWait As Boolean = False)
   Dim objWshShell As Object
   Set objWshShell = CreateObject("WScript.Shell")
   objWshShell.SendKeys Chr(p_iKeyCode), p_fWait
   Set objWshShell = Nothing
End Sub
Étienne Laneville
  • 4,697
  • 5
  • 13
  • 29
  • I tried Chr(179( with the following code but the pressed keyCode was 16. ``` Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) MsgBox KeyCode End Sub Private Sub Form_Load() SendKeys Chr(179) End Sub ``` – Stack Overflow User 13733624 Dec 01 '20 at 01:10
  • `Form_KeyDown` event should not occur when `SendKeys` is used. I have tried `SendKeysViaWshShell 179` here and it starts/stop my media player. Please update your question with your latest code so we can see what you are doing. – Étienne Laneville Dec 01 '20 at 05:01
  • I used your SendKeysViaWshShell function, but the KeyDown event occured, and the KeyCode was always 144. Note that I use Windows XP. – Stack Overflow User 13733624 Dec 01 '20 at 06:21
  • 1
    Please update your question with your latest code so we can see what you are doing. – Étienne Laneville Dec 01 '20 at 16:33