Results 1 to 4 of 4

Thread: Global Hotkeys

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Posts
    6

    Global Hotkeys

    I would like to get my program to hide when i press for example
    ctrl + alt + q
    (me.hide is what i would use) but how do you make global hotkeys?

    Please help ASAP
    Thanks

  2. #2
    Junior Member
    Join Date
    Apr 2003
    Location
    INDIA
    Posts
    20
    in vb i don't think any function for that, but u can use API's for that.

    use SetWindowsHookEx. the usage u can search in the MSDN. example also there in MSDN

    prince

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    It would be better/easier to use the RegisterHotKey API.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    VB Code:
    1. Private Const MOD_ALT = &H1
    2. Private Const MOD_CONTROL = &H2
    3. Private Const MOD_SHIFT = &H4
    4. Private Const PM_REMOVE = &H1
    5. Private Const WM_HOTKEY = &H312
    6. Private Type POINTAPI
    7.     x As Long
    8.     y As Long
    9. End Type
    10. Private Type Msg
    11.     hWnd As Long
    12.     Message As Long
    13.     wParam As Long
    14.     lParam As Long
    15.     time As Long
    16.     pt As POINTAPI
    17. End Type
    18. Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
    19. Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
    20. Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
    21. Private Declare Function WaitMessage Lib "user32" () As Long
    22. Private bCancel As Boolean
    23. Private Sub ProcessMessages()
    24.     Dim Message As Msg
    25.     'loop until bCancel is set to True
    26.     Do While Not bCancel
    27.         'wait for a message
    28.         WaitMessage
    29.         'check if it's a HOTKEY-message
    30.         If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
    31.             'minimize the form
    32.             WindowState = vbMinimized
    33.         End If
    34.         'let the operating system process other events
    35.         DoEvents
    36.     Loop
    37. End Sub
    38. Private Sub Form_Load()
    39.     'KPD-Team 2000
    40.     'URL: [url]http://www.allapi.net/[/url]
    41.     'E-Mail: [email][email protected][/email]
    42.     Dim ret As Long
    43.     bCancel = False
    44.     'register the Ctrl-F hotkey
    45.     ret = RegisterHotKey(Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyF)
    46.     'show some information
    47.     Me.AutoRedraw = True
    48.     Me.Print "Press CTRL-F to minimize this form"
    49.     'show the form and
    50.     Show
    51.     'process the Hotkey messages
    52.     ProcessMessages
    53. End Sub
    54. Private Sub Form_Unload(Cancel As Integer)
    55.     bCancel = True
    56.     'unregister hotkey
    57.     Call UnregisterHotKey(Me.hWnd, &HBFFF&)
    58. End Sub


    Has someone helped you? Then you can Rate their helpful post.

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