Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Detecting Keyboard strokes

Total Hit ( 15744)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
'In a module
'***************************
'* Keyboard constants
'***************************
Public Const VK_ACCEPT = &H1E
Public Const VK_ADD = &H6B
Public Const VK_APPS = &H5D
Public Const VK_ATTN = &HF6
Public Const VK_BACK = &H8
Public Const VK_BROWSER_BACK = &HA6
Public Const VK_BROWSER_FAVORITES = &HAB
Public Const VK_BROWSER_FORWARD = &HA7
Public Const VK_BROWSER_HOME = &HAC
Public Const VK_BROWSER_REFRESH = &HA8
Public Const VK_BROWSER_SEARCH = &HAA
Public Const VK_BROWSER_STOP = &HA9
Public Const VK_CANCEL = &H3
Public Const VK_CAPITAL = &H14
Public Const VK_CLEAR = &HC
Public Const VK_CONTROL = &H11
Public Const VK_CONVERT = &H1C
Public Const VK_CRSEL = &HF7
Public Const VK_DBE_ALPHANUMERIC = &HF0
Public Const VK_DBE_CODEINPUT = &HFA
Public Const VK_DBE_DBCSCHAR = &HF4
Public Const VK_DBE_DETERMINESTRING = &HFC
Public Const VK_DBE_ENTERDLGCONVERSIONMODE = &HFD
Public Const VK_DBE_ENTERIMECONFIGMODE = &HF8
Public Const VK_DBE_ENTERWORDREGISTERMODE = &HF7
Public Const VK_DBE_FLUSHSTRING = &HF9
Public Const VK_DBE_HIRAGANA = &HF2
Public Const VK_DBE_KATAKANA = &HF1
Public Const VK_DBE_NOCODEINPUT = &HFB
Public Const VK_DBE_NOROMAN = &HF6
Public Const VK_DBE_ROMAN = &HF5
Public Const VK_DBE_SBCSCHAR = &HF3
Public Const VK_DECIMAL = &H6E
Public Const VK_DELETE = &H2E
Public Const VK_DIVIDE = &H6F
Public Const VK_DOWN = &H28
Public Const VK_END = &H23
Public Const VK_EREOF = &HF9
Public Const VK_ESCAPE = &H1B
Public Const VK_EXECUTE = &H2B
Public Const VK_EXSEL = &HF8
Public Const VK_F1 = &H70
Public Const VK_F10 = &H79
Public Const VK_F11 = &H7A
Public Const VK_F12 = &H7B
Public Const VK_F13 = &H7C
Public Const VK_F14 = &H7D
Public Const VK_F15 = &H7E
Public Const VK_F16 = &H7F
Public Const VK_F17 = &H80
Public Const VK_F18 = &H81
Public Const VK_F19 = &H82
Public Const VK_F2 = &H71
Public Const VK_F20 = &H83
Public Const VK_F21 = &H84
Public Const VK_F22 = &H85
Public Const VK_F23 = &H86
Public Const VK_F24 = &H87
Public Const VK_F3 = &H72
Public Const VK_F4 = &H73
Public Const VK_F5 = &H74
Public Const VK_F6 = &H75
Public Const VK_F7 = &H76
Public Const VK_F8 = &H77
Public Const VK_F9 = &H78
Public Const VK_FINAL = &H18
Public Const VK_HANGEUL = &H15
Public Const VK_HANGUL = &H15
Public Const VK_HANJA = &H19
Public Const VK_HELP = &H2F
Public Const VK_HOME = &H24
Public Const VK_ICO_00 = &HE4
Public Const VK_ICO_CLEAR = &HE6
Public Const VK_ICO_HELP = &HE3
Public Const VK_INSERT = &H2D
Public Const VK_JUNJA = &H17
Public Const VK_KANA = &H15
Public Const VK_KANJI = &H19
Public Const VK_LAUNCH_APP1 = &HB6
Public Const VK_LAUNCH_APP2 = &HB7
Public Const VK_LAUNCH_MAIL = &HB4
Public Const VK_LAUNCH_MEDIA_SELECT = &HB5
Public Const VK_LBUTTON = &H1
Public Const VK_LCONTROL = &HA2
Public Const VK_LEFT = &H25
Public Const VK_LMENU = &HA4
Public Const VK_LSHIFT = &HA0
Public Const VK_LWIN = &H5B
Public Const VK_MBUTTON = &H4
Public Const VK_MEDIA_NEXT_TRACK = &HB0
Public Const VK_MEDIA_PLAY_PAUSE = &HB3
Public Const VK_MEDIA_PREV_TRACK = &HB1
Public Const VK_MEDIA_STOP = &HB2
Public Const VK_MENU = &H12
Public Const VK_MODECHANGE = &H1F
Public Const VK_MULTIPLY = &H6A
Public Const VK_NEXT = &H22
Public Const VK_NONAME = &HFC
Public Const VK_NONCONVERT = &H1D
Public Const VK_NUMLOCK = &H90
Public Const VK_NUMPAD0 = &H60
Public Const VK_NUMPAD1 = &H61
Public Const VK_NUMPAD2 = &H62
Public Const VK_NUMPAD3 = &H63
Public Const VK_NUMPAD4 = &H64
Public Const VK_NUMPAD5 = &H65
Public Const VK_NUMPAD6 = &H66
Public Const VK_NUMPAD7 = &H67
Public Const VK_NUMPAD8 = &H68
Public Const VK_NUMPAD9 = &H69
Public Const VK_OEM_1 = &HBA
Public Const VK_OEM_102 = &HE2
Public Const VK_OEM_2 = &HBF
Public Const VK_OEM_3 = &HC0
Public Const VK_OEM_4 = &HDB
Public Const VK_OEM_5 = &HDC
Public Const VK_OEM_6 = &HDD
Public Const VK_OEM_7 = &HDE
Public Const VK_OEM_8 = &HDF
Public Const VK_OEM_ATTN = &HF0
Public Const VK_OEM_AUTO = &HF3
Public Const VK_OEM_AX = &HE1
Public Const VK_OEM_BACKTAB = &HF5
Public Const VK_OEM_CLEAR = &HFE
Public Const VK_OEM_COMMA = &HBC
Public Const VK_OEM_COPY = &HF2
Public Const VK_OEM_CUSEL = &HEF
Public Const VK_OEM_ENLW = &HF4
Public Const VK_OEM_FINISH = &HF1
Public Const VK_OEM_FJ_JISHO = &H92
Public Const VK_OEM_FJ_LOYA = &H95
Public Const VK_OEM_FJ_MASSHOU = &H93
Public Const VK_OEM_FJ_ROYA = &H96
Public Const VK_OEM_FJ_TOUROKU = &H94
Public Const VK_OEM_JUMP = &HEA
Public Const VK_OEM_MINUS = &HBD
Public Const VK_OEM_NEC_EQUAL = &H92
Public Const VK_OEM_PA1 = &HEB
Public Const VK_OEM_PA2 = &HEC
Public Const VK_OEM_PA3 = &HED
Public Const VK_OEM_PERIOD = &HBE
Public Const VK_OEM_PLUS = &HBB
Public Const VK_OEM_RESET = &HE9
Public Const VK_OEM_WSCTRL = &HEE
Public Const VK_PA1 = &HFD
Public Const VK_PACKET = &HE7
Public Const VK_PAUSE = &H13
Public Const VK_PLAY = &HFA
Public Const VK_PRINT = &H2A
Public Const VK_PRIOR = &H21
Public Const VK_PROCESSKEY = &HE5
Public Const VK_RBUTTON = &H2
Public Const VK_RCONTROL = &HA3
Public Const VK_RETURN = &HD
Public Const VK_RIGHT = &H27
Public Const VK_RMENU = &HA5
Public Const VK_RSHIFT = &HA1
Public Const VK_RWIN = &H5C
Public Const VK_SCROLL = &H91
Public Const VK_SELECT = &H29
Public Const VK_SEPARATOR = &H6C
Public Const VK_SHIFT = &H10
Public Const VK_SLEEP = &H5F
Public Const VK_SNAPSHOT = &H2C
Public Const VK_SPACE = &H20
Public Const VK_SUBTRACT = &H6D
Public Const VK_TAB = &H9
Public Const VK_UP = &H26
Public Const VK_VOLUME_DOWN = &HAE
Public Const VK_VOLUME_MUTE = &HAD
Public Const VK_VOLUME_UP = &HAF
Public Const VK_XBUTTON1 = &H5
Public Const VK_XBUTTON2 = &H6
Public Const VK_ZOOM = &HFB
'***************************
Public Const WH_KEYBOARD = 2

Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
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
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long

Public hHook As Long
Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  'if idHook is less than zero, no further processing is required
  If idHook < 0 Then
    'call the next hook
    KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
  Else
    'check if SHIFT-S is pressed
    If (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc("S") Then
      'show the result
      Form1.Print "Shift-S pressed ..."
    End If
    'call the next hook
    KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
  End If
End Function


'******************************
' In the form
'******************************



'In a form, called Form1
Private Sub Form_Load()
  'set a keyboard hook
  hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)
End Sub
Private Sub Form_Unload(Cancel As Integer)
  'remove the windows-hook
  UnhookWindowsHookEx hHook
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.