hello how i can make multi short key? (VB2010)
-
Friday, June 08, 2012 4:15 PM
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown Dim mydata As Object mydata = e.KeyCode TextBox1.Text = mydata.ToString 'when i enter 'Q' key output(textbox1.text) = 'qQ' how Show Q only''' 'and how i can set multi shortkey output = CTRL+TAB+CAPS LOCK,and bla bla , and send to Timer1' End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 'if im press hotkey (textbox1.text) Then 'Button1.PerformClick() 'end if End Sub
All Replies
-
Monday, June 11, 2012 6:09 AMModerator
Hi NabiNeji,
Welcome to the MSDN forum.
Please take a look at this VB FAQ:http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/c1a24688-d844-4adc-9d85-416a7158c6ba about register a hotkey in VB.NET. I added some codes for you in this example below.
Imports System.Runtime.InteropServices Public Class Form1 Public Const MOD_ALT As Integer = &H1 'Alt key Public Const WM_HOTKEY As Integer = &H312 Private Const MOD_CONTROL As Integer = 2 Private Const MOD_SHIFT As Integer = 4 Private Const MOD_WIN As Integer = 8 Const VK_CAPITAL = &H14 <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 Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load RegisterHotKey(Me.Handle, 100, MOD_ALT Or MOD_CONTROL, VK_CAPITAL) RegisterHotKey(Me.Handle, 200, MOD_ALT, Keys.C) End Sub 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 CTRL+ALT+CAPS key combination") Case "200" MessageBox.Show("You pressed ALT+C key combination") End Select 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, 100) UnregisterHotKey(Me.Handle, 200) End Sub End Class
I hope this will be helpful.
Best regards,
Shanks Zen
MSDN Community Support | Feedback to us
- Marked As Answer by Shanks ZenMicrosoft Contingent Staff, Moderator Thursday, June 21, 2012 8:24 AM
-
Monday, June 11, 2012 8:52 AM
about multi shortkey problem you can use this code
and about your first problem ... your typing in the text box, when you press 'Q' the text property of text box changes. i dont understand why you'r trying to get the keycode and show it in a text box . try a lable or something else ...If e.KeyCode = Keys.C AndAlso e.Modifiers = (Keys.Control Or Keys.Shift) Then 'code ElseIf e.KeyCode = Keys.V AndAlso e.Modifiers = Keys.Control Then
'code End If
- Edited by Pooyan Fekrati Monday, June 11, 2012 8:53 AM
- Marked As Answer by Shanks ZenMicrosoft Contingent Staff, Moderator Thursday, June 21, 2012 8:24 AM

