GFGlobalKeyHook2/Testfrm.frm
VERSION 5.00
Begin VB.Form Testfrm
Caption = "Form1"
ClientHeight = 3144
ClientLeft = 60
ClientTop = 432
ClientWidth = 4692
LinkTopic = "Form1"
ScaleHeight = 3144
ScaleWidth = 4692
StartUpPosition = 3 'Windows‑Standard
Begin VB.TextBox Text1
Height = 2532
Left = 120
MultiLine = ‑1 'True
TabIndex = 1
Top = 480
Width = 4452
End
Begin VB.PictureBox KH
Enabled = 0 'False
Height = 315
Left = 0
ScaleHeight = 264
ScaleWidth = 144
TabIndex = 0
TabStop = 0 'False
Top = 0
Visible = 0 'False
Width = 195
End
End
Attribute VB_Name = "Testfrm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'(c)2004, 2011 by Louis. Test form for GFGlobalKeyHookmod.
'
'Downloaded from www.louis‑coder.com.
'Use the interface to this global key hook implementation to create Windows‑wide
'hot keys or to build keyloggers. Don't forget to copy the hook dll to the client machine
'(into the program directory or Windows‑directory).
'
'GFGlobalKeyHookProc
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function ToAscii Lib "user32" (ByVal uVirtKey As Long, ByVal uScanCode As Long, lpbKeyState As Byte, lpwTransKey As Long, ByVal fuState As Long) As Long
'GFGlobalKeyHookProc
Private Const VK_LSHIFT = &HA0
Private Const VK_LMENU = &HA4
Private Const VK_LCONTROL = &HA2
Private Const VK_RMENU = &HA5
Private Const VK_RSHIFT = &HA1
Private Const VK_RCONTROL = &HA3
Private Sub Form_Load()
'on error resume next
Call GFGlobalKeyHook_SetKeyHook("Testfrm", Testfrm)
End Sub
Public Sub GFGlobalKeyHookProc(ByVal SourceDescription As String, ByVal KeyCode As Integer, ByVal Shift As Integer, ByRef ReturnValueUsedFlag As Boolean, ByRef ReturnValue As Long)
'on error resume next
Debug.Print "SourceDescription=" & SourceDescription
Debug.Print "KeyCode=" & KeyCode
Debug.Print "Shift=" & Shift
If (KeyCode = 65) Then
ReturnValueUsedFlag = True 'does NOT work in global version (merely in GFKeyHook)
ReturnValue = 1 'A/a is disabled 'does NOT work in global version (merely in GFKeyHook)
End If
'
Dim KeyboardStateCurrent(0 To 255) As Byte
Dim KeyTranslated As Long
Dim KeyScanCode As Long
'
'NOTE: GetKeyboardState() did not work right.
'Now we do it 'manually' like this:
'
If (GetAsyncKeyState(VK_LSHIFT) Or GetAsyncKeyState(VK_RSHIFT)) Then KeyboardStateCurrent(vbKeyShift) = &H80
If (GetAsyncKeyState(VK_LCONTROL) Or GetAsyncKeyState(VK_RCONTROL)) Then KeyboardStateCurrent(vbKeyControl) = &H80
If (GetAsyncKeyState(VK_RMENU)) Then KeyboardStateCurrent(vbKeyMenu) = &H80
'
Call ToAscii(KeyCode, KeyScanCode, KeyboardStateCurrent(0), KeyTranslated, 0)
'
'TODO: if a key you press does not appear in Form1.Text1, see what
'KeyCode it has (see Debug Window (open it by pressing Ctrl‑G)) and
'process that KeyCode in the following Select‑statement:
'
Select Case KeyCode
Case 10, 13
Text1.Text = Text1.Text & vbNewLine
Case 112
Text1.Text = Text1.Text & "[F1]"
Case 113
Text1.Text = Text1.Text & "[F2]"
Case 114
Text1.Text = Text1.Text & "[F3]"
Case 115
Text1.Text = Text1.Text & "[F4]"
Case 116 'the 116 here
'Debug Window would show:
'SourceDescription=Testfrm
'KeyCode = 116
'Shift = 0
Text1.Text = Text1.Text & "[F5]" 'add what is to be printed for that key here (e.g. "[F5]")
Case 117
Text1.Text = Text1.Text & "[F6]"
Case 118
Text1.Text = Text1.Text & "[F7]"
Case 119
Text1.Text = Text1.Text & "[F8]"
Case 120
Text1.Text = Text1.Text & "[F9]"
Case 121
Text1.Text = Text1.Text & "[F10]"
Case 122
Text1.Text = Text1.Text & "[F11]"
Case 123
Text1.Text = Text1.Text & "[F12]"
'TODO: add further "Case ..." and what is to be added to Text1 (continue the existing Case‑list)
Case Else
Text1.Text = Text1.Text & Chr$(KeyTranslated)
End Select
End Sub
Private Sub Form_Unload(Cancel As Integer)
'on error resume next
Call GFGlobalKeyHook_Terminate 'important, call when your project is exited
End Sub
[END OF FILE]