N M
asked on
Custom Function keys - set function keys to CTRL+B, CTRL+F..
For my own needs, I need a small application that would set the function keys to specific keystrokes:
F1 set to CTRL+U + CTRL+M
F2 set to CTRL+B + CTRL+M
F3 set to CTRL+F + CTRL+M
F4 set to CTRL+E + CTRL+M
F5 set to CTRL+V + V + + CTRL+M
F6 set to CTRL+W + CTRL+M
F7 set to CTRL+T + CTRL+M
This means that if I press F5, it should be like pressing CTRL+V, then the letter V, and then CTRL+M. How should I do that?
F1 set to CTRL+U + CTRL+M
F2 set to CTRL+B + CTRL+M
F3 set to CTRL+F + CTRL+M
F4 set to CTRL+E + CTRL+M
F5 set to CTRL+V + V + + CTRL+M
F6 set to CTRL+W + CTRL+M
F7 set to CTRL+T + CTRL+M
This means that if I press F5, it should be like pressing CTRL+V, then the letter V, and then CTRL+M. How should I do that?
Do you want to achieve this in your application only or globally? If you want it globally you would need to use a low level keyboard hook and this would disable the function keys from any other action. If you want it only in your application you can set keypreview to true on your form and handle the KeyUp event. You could then send the appropriate keys when the selected function key was clicked. If you can clarify the method you are looking for, I can provide an example.
Also, please let us know what version VB you're using...there's a HUGE difference between VBScript (.vbs) and VB.Net...
ASKER
THANK YOU indeed for your comment. In fact, I can use 2003 or 2005 versions of VB .NET, I just putted vb script in case I can solve this without compiling ..
Yes, as a fast solution, I would like to permanently change the behaviour of the function keys (well, it would be nice if I could reverse this later on in the future)
THANK YOU
Nick
Yes, as a fast solution, I would like to permanently change the behaviour of the function keys (well, it would be nice if I could reverse this later on in the future)
THANK YOU
Nick
You can use the global keyboard hooks and replace the e.keychar appropriately. Following articles are in C# but may be useful
http://www.codeproject.com/KB/cs/CSLLKeyboardHook.aspx
http://www.codeproject.com/KB/cs/globalhook.aspx
http://www.codeproject.com/KB/cs/CSLLKeyboardHook.aspx
http://www.codeproject.com/KB/cs/globalhook.aspx
ASKER
I will look, but I would appreciate if we could do something in VB .NET...
THANK YOU
THANK YOU
I have a HookManager.dll that I use for global hooks. I can't share the source but you are welcome to use the dll. The dll is written in C#. It is available here http://ffxilinkshell.com/apps/Hook.dll
Usage is as follows below. I made a quick project that should do what you are asking
Usage is as follows below. I made a quick project that should do what you are asking
Imports Hook
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler HookManager.KeyDown, AddressOf HookManager_KeyDown
AddHandler HookManager.KeyUp, AddressOf HookManager_KeyUp
End Sub
Private Sub HookManager_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
Select Case e.KeyCode
Case Keys.F1
e.Handled = True
Case Keys.F2
e.Handled = True
Case Keys.F3
e.Handled = True
Case Keys.F4
e.Handled = True
Case Keys.F5
e.Handled = True
Case Keys.F6
e.Handled = True
Case Keys.F7
e.Handled = True
End Select
End Sub
Private Sub HookManager_KeyUp(ByVal sender As Object, ByVal e As KeyEventArgs)
Select Case e.KeyCode
Case Keys.F1
e.Handled = True
SendKeys.Send("^u")
SendKeys.Send("^m")
Case Keys.F2
e.Handled = True
SendKeys.Send("^b")
SendKeys.Send("^m")
Case Keys.F3
e.Handled = True
SendKeys.Send("^f")
SendKeys.Send("^m")
Case Keys.F4
e.Handled = True
SendKeys.Send("^e")
SendKeys.Send("^m")
Case Keys.F5
e.Handled = True
SendKeys.Send("^v")
SendKeys.Send("v")
SendKeys.Send("^m")
Case Keys.F6
e.Handled = True
SendKeys.Send("^w")
SendKeys.Send("^m")
Case Keys.F7
e.Handled = True
SendKeys.Send("^t")
SendKeys.Send("^m")
End Select
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Checking both solutions. Thank you indeed; by Monday I will be ready to answer (the final test will be done in another desktop so I need to be sure for the functionality on that system).
I will use vb .net 2005
I will use vb .net 2005
ASKER
Sorry for delay, I think the autonomous solution is what I was looking for.
Thank you all
Nick
Thank you all
Nick