Click to See Complete Forum and Search --> : Problem with hotkey binds


Junday
September 2nd, 2009, 11:07 AM
Hello out there :-)

I am making a macro program, which should write a text when i click on a specify key on keyboard. I use F keys from F1 to F10 and my program works fine...

The only problem i get is that the F1 key call the Help-box and F2 call the Find-box e.g. but i wanted to know, if its possible on a easy way that would disable them, and only react on send text i wan't without calling these...

I use GetAsyncKeystate Function with Boolean.

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer

and my F1 key (Timer Tick) look like this:

Private Sub bindf1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bindf1.Tick
Dim bindf1 As Boolean
bindf1 = GetAsyncKeyState(Keys.F1)
If bindf1 = True Then
SendKeys.Send(F1_txt.Text)
SendKeys.Send("{Enter}")
End If
End Sub

It works great, but the only problem is it calls the HELP-box which i don't want...

Thank you :-)

HanneSThEGreaT
September 3rd, 2009, 01:12 AM
I sat with a similar situation quite recently. There is no way to disable the built in functionality of a certain Key like F1 in a program, so however you manage to press the key, it will always do what it was intended to do.

Or, so I thought :)

Two APIs will be needed : UnregisterHotKey and RegisterHotKey. Once you have registered a certain Hotkey and override the WM_HOTKEY message; there you go! :)

There is a component I use with success in cases like this, and you can find it here :

http://www.codeproject.com/KB/vb/mclhotkeynet.aspx?msg=1808073

http://www.vbforums.com/showthread.php?t=249194

Just a note : If there is absolutely no other keys that you can actually use for this purpose, then doing this is fine, you'll just have to remember that the F keys have specific functions people are accustomed to - I'd actually say that you should rather choose different keys...

I hope my advice was helpful

dglienna
September 3rd, 2009, 01:41 AM
You know that's always going to bring a question down the line (a few months?) about Ctrl-Alt-Del...

Look up GINA (which controls special keys)