![]() |
|
Setting hotkey of textbox - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework) +--- Thread: Setting hotkey of textbox (/Thread-Setting-hotkey-of-textbox) |
Setting hotkey of textbox - absde20 - 03-17-2013 how can set keys Through textbox Like This Code: Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
If keyData = (TextBox1.Text) Then
Label1.Text = TextBox1.Text
End If
End FunctionCode: Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
If keyData = (Keys.A) Then
Label1.Text = TextBox1.Text
End If
End Functionso how i can do this any one have a idea ! -Thread title changed by Moderator RE: Any One can help me here ! - Coder-san - 03-17-2013 I have no idea what you just said there^ RE: Any One can help me here ! - Linuxephus™ - 03-18-2013 It's precisely 10:57pm EST here Stateside. As such, that's roughly 1 hour before my brain goes into Brain Dead Mode as is customary at said time. Thus will I translate the above for you on the morrow...or maybe the morrow after the morrow. RE: Any One can help me here ! - absde20 - 03-18-2013 (03-17-2013, 11:12 PM)Coder-san Wrote: I have no idea what you just said there^ok  i mean how can set hot key of textbox (03-18-2013, 03:59 AM)Linuxephus Wrote: It's precisely 10:57pm EST here Stateside. :angel:
RE: Setting hotkey of textbox - ArkPhaze - 03-19-2013 Use the PreviewKeyDown event, because it happens beforehand... C#, but easily, you should be able to see what i'm doing with this: Code: void Form1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyData == Keys.A)
{
// Do something?
}
}http://msdn.microsoft.com/en-us/library/system.windows.forms.control.previewkeydown.aspx MSDN Wrote:Occurs before the KeyDown event when a key is pressed while focus is on this control. Read the Remarks as it is important, and look at the example code with the VB tab selected to view the VB.NET version. If you want to use a Key event, there's KeyDown and KeyUp as well, but I would highly recommend KeyUp over the KeyDown, and for a few reasons. RE: Setting hotkey of textbox - RA1N - 03-20-2013 orrrrr.... Code: Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As ShortCode: Public Function GetKeyState(ByVal key As Integer) As Boolean
Dim s As Short
s = GetAsyncKeyState(key)
If s = 0 Then Return False
Return True
End FunctionCode: If GetKeyState(Keys.*) = True Then
'put this if statement in a thread to run through to keep a check on it.
End IfThis way it checks through out the whole time while running the program for a hotkey. RE: Setting hotkey of textbox - ArkPhaze - 03-20-2013 (03-20-2013, 01:22 AM)RA1N Wrote: orrrrr.... Perhaps, but you have to call it multiple times to make sure that it hits the time a user presses a key because it's not based on events. He wanted a hotkey for specifically a textbox as I read it. If you wanted a global system-wide hotkey, you could do it this way, but it is a very poor way, and it uses a lot of resources because it has to be called constantly. There's much better ways, even avoiding this, and a keyboard hook, but a keyboard hook is the ultimate way in my opinion, because you don't have to register and unregister a specific hotkey that may already be taken by something else. |