Results 1 to 3 of 3

Thread: System Wide Hotkey

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    2

    System Wide Hotkey

    Hi,

    I have a DLL that creates a system-wide hook, which can be used in VB6. Whenever I use it, my computer is fine, but when it's turned off, it goes all weird, windows don't minimize correctly and don't appear in the tray etc. Does anyone know why this would be the case?

    The dll is avaliable from:
    http://www.freevbcode.com/ShowCode.A...20hook&ID=1308

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: System Wide Hotkey



    To set system wide hot key you can use the following code:
    VB Code:
    1. Option Explicit
    2.  
    3. 'API Constants & Declarations
    4. Public Const GWL_WNDPROC As Long = (-4)
    5. Public Const WM_HOTKEY As Long = &H312
    6. Public Const MOD_ALT = &H1
    7. Public Const MOD_CONTROL = &H2
    8. Public Const MOD_SHIFT = &H4
    9.  
    10. Public Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Long
    11. Public Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal nAtom As Long) As Long
    12. Public Declare Function RegisterHotKey Lib "User32" (ByVal hWND As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
    13. Public Declare Function UnregisterHotKey Lib "User32" (ByVal hWND As Long, ByVal id As Long) As Long
    14. Public Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWND As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    15. Public Declare Function CallWindowProc Lib "User32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWND As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    16. Public mlngLastWndProc As Long
    17. Public mlngAtom As Long
    18.  
    19. 'Functions and Subroutines to store in main module
    20. 'Function which determines what happens when HotKey pressed
    21. Function WindowProc(ByVal hWND As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    22.     If hWND = Clipboard_Mgr_Frm.hWND And uMsg = WM_HOTKEY Then
    23.         Clipboard_Mgr_Frm.Text1.Text = Clipboard_Mgr_Frm.Text1.Text & Clipboard.GetText(vbCFText) & vbCrLf & vbCrLf
    24.     End If
    25.     WindowProc = CallWindowProc(mlngLastWndProc, hWND, uMsg, wParam, lParam)
    26. End Function
    27.  
    28. 'Subroutine which creates the Hot Key
    29. Public Sub CreateHotKey(ByVal intKeyCode As Integer, ByVal hWND As Long)
    30.     mlngAtom = GlobalAddAtom(CStr(Now))
    31.     mlngLastWndProc = SetWindowLong(hWND, GWL_WNDPROC, AddressOf WindowProc)
    32.     RegisterHotKey hWND, mlngAtom, 0, intKeyCode
    33. End Sub
    34.  
    35. 'Subroutine which destroys the hot key
    36. Public Sub DestroyHotKey(ByVal hWND As Long)
    37.     UnregisterHotKey hWND, GlobalDeleteAtom(mlngAtom)
    38.     Call SetWindowLong(hWND, GWL_WNDPROC, mlngLastWndProc)
    39. End Sub
    40.  
    41. 'Procedures in a particular form
    42. Private Sub Form_Load()
    43.     CreateHotKey vbKeyF2, Me.hWND
    44.     ' Message below to let user know hot key has been created and what it does.
    45.     MsgBox "F2 is now a HOT KEY which will copy the clipboard contents" & vbCrLf & _
    46.            "To the textbox (minimized) — from ANYWHERE on the system!" & vbCrLf & vbCrLf & _
    47.            "REMEMBER to hit both Ctrl + C and F2 when copying text." & vbCrLf & vbCrLf & _
    48.            "MAXIMIZE from the Taskbar to Insert text in Word document.", vbOKOnly, _
    49.            "                               HOT KEY F2 PROCESS START"
    50. End Sub
    51.  
    52. 'Remember to destroy hot key when exiting the form
    53. Private Sub cmdExit_Click()
    54.     DestroyHotKey Me.hWND
    55.     Unload Me
    56.     End
    57. End Sub
    CS

  3. #3
    Lively Member
    Join Date
    Jul 2006
    Posts
    110

    Re: System Wide Hotkey

    I use this and when i click exit or stop the run, Visual Basic Shuts down also and i lose all unsaved work. Why is this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width