Results 1 to 2 of 2

Thread: [Resolved][2008]hotkeys the shorter way ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    74

    [Resolved][2008]hotkeys the shorter way ?

    All the codes to declare 1 single Global hotkey I found are just huge, I mean they are really really long. Isnt there a shorter way to do this? something like this maybe?
    Code:
        HotKeySet("{F5}", "_testfunc") 
    
        Sub _testfunc()
            HotKeySet("{F5}") ' unreg hotkey
        End Sub
    Last edited by goldenix; Apr 10th, 2008 at 06:24 PM.

    M.V.B. 2008 Express Edition

  2. #2
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2008]hotkeys the shorter way ?

    ou want a hotkey to work if your application is in focus then your hotkey code will be extremely simple.
    If you wnat a global hotkey then you have to use those complicated codes involving windows API.

    The following code is as short as i can get to a global hotkey:

    Code:
    Private Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
        Private Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
        Public Const WM_HOTKEY As Integer = &H312
    
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            RegisterHotKey(Me.Handle.ToInt32, 0, 0, System.Windows.Forms.Keys.F11)'edit this for the hotkey you want
        End Sub
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            If m.Msg = WM_HOTKEY Then
              'code for if they press hotkey here   
                Else  
                End If
            End If
            MyBase.WndProc(m)
        End Sub
    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
                       UnregisterHotKey(Me.Handle.ToInt32, 0)
               End Sub
    If this post helped you, please click the rate button to say thank you! Remember to mark the thread as resolved too.
    Autoclicker, Hide Taskbar, Sounds on internal speaker, Changing Start Button Text (with code)

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