Reputation: 547
EDIT: I found an article that lists exactly what I needed: http://msdn.microsoft.com/en-us/library/ms646309(v=vs.85).aspx
Thanks for your help!
Original:
I'm wondering what keyboard keys are represented by the &H
hex codes?
For example, I've found that &H1
is the ALT key, &H2
is the CONTROL key, and &H3
is both the ALT and CONTROL keys together. &H10
is the Shift key, it appears. I'm asking because I need to find out for a program I'm designing that needs to register a hotkey. The user has the option to hide it, and I want to make sure that they can show it again by pressing a hotkey, but I need to figure out what the hex keys are to use the code that I found.
Here's part of the code I found:
Public Const MOD_ALT As Integer = &H1 'Alt key
Public Const WM_HOTKEY As Integer = &H312
<DllImport("User32.dll")> _
Public Shared Function RegisterHotKey(ByVal hwnd As IntPtr, _
ByVal id As Integer, ByVal fsModifiers As Integer, _
ByVal vk As Integer) As Integer
End Function
<DllImport("User32.dll")> _
Public Shared Function UnregisterHotKey(ByVal hwnd As IntPtr, _
ByVal id As Integer) As Integer
End Function
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_HOTKEY Then
Dim id As IntPtr = m.WParam
Select Case (id.ToString)
Case "100"
MessageBox.Show("You pressed ALT+D key combination")
Case "200"
MessageBox.Show("You pressed ALT+C key combination")
End Select
End If
MyBase.WndProc(m)
End Sub
And this registers the hotkeys when the form loads:
RegisterHotKey(Me.Handle, 100, &H3, Keys.D)
RegisterHotKey(Me.Handle, 200, Keys.Alt, Keys.C)
This is the thread I was looking at on the MSDN forums -- I copied the code from the featured answer.
I've done a thorough Google search and I've searched here on StackOverflow, and I can't find anything.
Is there maybe a list of the hex codes somewhere, or instructions or something?
Thanks!
Upvotes: 0
Views: 9443
Reputation: 8084
In that MSDN thread you've linked there is a link to Virtual Key Codes. In addition, check the System.Windows.Forms.Keys enumeration.
Notice that the RegisterHotKey method takes the following arguments: hWnd, id, fsModifiers and vk. VK is where you place the VirtualKey code. Regarding fsModifiers:
The keys that must be pressed in combination with the key specified by the uVirtKey parameter in order to generate the WM_HOTKEY message. The fsModifiers parameter can be a combination of the following values: MOD_ALT (0x0001), MOD_CONTROL (0x0002), MOD_NOREPEAT (0x4000), MOD_SHIFT (0x0004), MOD_WIN (0x0008).
Upvotes: 1