i want to make a hotkeys app ...
i need to detect keystrokes even if the form is not active so that by pressing a button i can launh the calculator.... or games and stuff like that...
any ideas ?
Thank you
i want to make a hotkeys app ...
i need to detect keystrokes even if the form is not active so that by pressing a button i can launh the calculator.... or games and stuff like that...
any ideas ?
Thank you
One way to do this, Register you hot key in Registry. Or Hook the Keyboard Procedure. The second one is hard.
can you write an example of the code needed to do this because i dont understand this by reading it in the msdn....
Thank you
I give example using Win32 API. You have to refer it. I am not sure it is error free. But just try
Draw a form and Try this code. Run the Project. Press Ctrl + Alt + Up Arrow
Public Enum HotKeyModifiers As Integer
MOD_ALT = &H1
MOD_CONTROL = &H2
MOD_SHIFT = &H4
MOD_WIN = &H8
End Enum
Private Const WM_HOTKEY As Integer = &H312
Public Declare Auto Function RegisterHotKey Lib "user32" (ByVal hWnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Boolean
Public Declare Auto Function UnregisterHotKey Lib "user32" (ByVal hWnd As IntPtr, ByVal id As Integer) As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RegisterHotKey(Me.Handle, 1020, HotKeyModifiers.MOD_ALT Or HotKeyModifiers.MOD_CONTROL, Keys.Up)
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
UnregisterHotKey(Me.Handle, 1020)
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If (m.Msg = WM_HOTKEY) Then
Dim hotKeyId As Integer = m.WParam.ToInt32()
If hotKeyId = 1020 Then
MsgBox("Hot Key Pressed")
End If
End If
End Sub
Great code
Thanks Jx_Man
Thank you .... that helped a lot...
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.