0

It's quite simple really. I want for an application to keep monitoring KeyDown events even without focus.

Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    Select Case e.KeyData
        Case Keys.MediaStop
            PictureBox2_Click(sender, e)
        Case Keys.MediaPlayPause
            PauseToolStripMenuItem_Click(sender, e)
        Case Keys.MediaNextTrack
            SkipTrackToolStripMenuItem_Click(sender, e)
        Case Keys.MediaPreviousTrack
            PreviousTrackToolStripMenuItem_Click(sender, e)
    End Select
End Sub

The above code is for a music player. Functions are called when the media keys are pressed ('Fn'+ 'Home', 'Fn' + 'Pg Up'...etc)

In a previous comment, somebody suggested looking into WH_KEYBOARD_LL for a solution but I didn't really understand much of it, if I'm honest.

UPDATE:

The link suggested isn't great as the 'As Any' keyword is not supported in 'Declare' functions.

This is how far I've got with it...

Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As **Any**) As Long

Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long

Public Declare Function SetWindowsHook Lib "user32" Alias "SetWindowsHookA" (ByVal nFilterType As Long, ByVal pfnFilterProc As Long) As Long

Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As **Any**, Source As **Any**, ByVal Length As Long)

**Global** Const WH_KEYBOARD_LL = 13
Public Const HC_ACTION = 0

Structure HookStruct
    Dim vkCode As Long
    Dim scancode As Long
    Dim flags As Long
    Dim time As Long
    Dim dwExtraInfo As Long
End Structure

The errors that Visual Studio is underlining are all written in bold On hover of 'Any' it gives me the message "'As Any' is not supported in 'Declare' statements"

On hover of 'Global' it gives "Syntax error"

rags
  • 2,580
  • 19
  • 37
Josh-Mason
  • 319
  • 3
  • 8
  • 22

2 Answers2

0

Implementing Keyboard hook using Windows API is the solution. Please check : http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=13506&lngWId=1

rags
  • 2,580
  • 19
  • 37
  • Check 1. http://msdn.microsoft.com/en-us/library/347xhy8d.aspx 2. http://www.codeproject.com/Articles/8641/Equivalent-of-CopyMemory-in-NET...... For .NET version, check this link: http://sim0n.wordpress.com/2009/03/28/vbnet-keyboard-hook-class/ – rags Jul 18 '13 at 04:29
0

If you are using VB6 and want to Hide the Navigation Bar, simply do this.

aw$ = "^(h)" SendKeys aw$

Apply this after pdf file loads.

Randy
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 14 '22 at 19:19