Question

Custom Function keys - set function keys to CTRL+B, CTRL+F..

Asked by: mechanism

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?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-22 at 08:31:51ID24834922
Topics

VB Script

,

Microsoft Visual Basic.Net

Participating Experts
3
Points
500
Comments
9

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. ESC ALT CTRL SHIFT and F2 F3 F4 F5 pressed event ca…
    I'd like to capture the pressed event of ESC ALT CTRL F2 F3 F4 F5 SHIFT buttons but I don't know how code them Here the example: var keyChar = String.fromCharCode(e.which); if (keyChar == 'ESC'){document.forms[1].submit();return false;} ^^^ Any suggestion? ...
  2. VC++ keystroke analysis
    Dear All, I would like to know how to go about writing the code for storing(in a file) whatever the user types(keystrokes) on Windows NT environment. The functions used here are: 1. SetWindowsHookEx 2. WH_KEYBOARD 3. WM_KEYUP 4. WM_KEYDOWN Please help me with the code as...
  3. Ctrl+F4 not functioning in XP
    I am used to using Ctrl+F4 for closing child windows in Eudora. In my new Win XP work computer, Ctrl+F4 does nothing in any application, and Ctrl+W can only be used. Ctl+F6 also fails to switch windows. These are standard windows shortcuts and no longer work in other applic...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: bhmahlerPosted on 2009-10-22 at 10:58:29ID: 25637116

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.

 

by: Idle_MindPosted on 2009-10-22 at 12:08:36ID: 25637812

Also, please let us know what version VB you're using...there's a HUGE difference between VBScript (.vbs) and VB.Net...

 

by: mechanismPosted on 2009-10-23 at 02:16:34ID: 25642542

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

 

by: CodeCruiserPosted on 2009-10-23 at 04:55:20ID: 25643461

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

 

by: mechanismPosted on 2009-10-23 at 06:08:34ID: 25643965

I will look, but I would appreciate if we could do something in VB .NET...

THANK YOU

 

by: bhmahlerPosted on 2009-10-23 at 06:40:48ID: 25644292

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

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
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:

Select allOpen in new window

 

by: Idle_MindPosted on 2009-10-23 at 08:10:00ID: 25645149

Here's one written completely in VB.Net.

As stated in the Load() Event, the hook does not work while in the Visual Studio IDE.  Run the EXE in the \bin\release folder instead:

Imports System.Runtime.InteropServices
Public Class Form1
 
    Private SCH As ShortCutHook
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' *** Hook does NOT work while in the Visual Studio IDE...run the EXE in \bin\release directly! ***
        SCH = New ShortCutHook
    End Sub
 
    Private Class ShortCutHook
 
        Private Const HC_ACTION As Integer = 0
        Private Const WH_KEYBOARD_LL As Integer = 13
        Private Const WM_KEYDOWN As Integer = &H100
        Private Const WM_KEYUP As Integer = &H101
 
        Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, _
            ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
 
        Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" _
            (ByVal wCode As Integer, ByVal wMapType As Integer) As Integer
 
        Public Structure KBDLLHOOKSTRUCT
            Public vkCode As Integer
            Public scancode As Integer
            Public flags As Integer
            Public time As Integer
            Public dwExtraInfo As Integer
        End Structure
 
        Private Declare Function SetWindowsHookEx Lib "user32" _
            Alias "SetWindowsHookExA" ( _
            ByVal idHook As Integer, _
            ByVal lpfn As LowLevelKeyboardProcDelegate, _
            ByVal hmod As Integer, _
            ByVal dwThreadId As Integer) As Integer
 
        Private Declare Function CallNextHookEx Lib "user32" ( _
            ByVal hHook As Integer, _
            ByVal nCode As Integer, _
            ByVal wParam As Integer, _
            ByVal lParam As KBDLLHOOKSTRUCT) As Integer
 
        Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
            ByVal hHook As Integer) As Integer
 
        Private Delegate Function LowLevelKeyboardProcDelegate( _
            ByVal nCode As Integer, _
            ByVal wParam As Integer, _
            ByRef lParam As KBDLLHOOKSTRUCT) As Integer
 
        Public Event KeyDown(ByVal Key As Keys)
 
        Private hhkLowLevelKeyboard As Integer
        Private keyboardDelegate As LowLevelKeyboardProcDelegate
 
        Public Sub New()
            keyboardDelegate = New LowLevelKeyboardProcDelegate(AddressOf Me.LowLevelKeyboardProc)
            hhkLowLevelKeyboard = SetWindowsHookEx(WH_KEYBOARD_LL, keyboardDelegate, _
                Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
        End Sub
 
        Private Function LowLevelKeyboardProc( _
            ByVal nCode As Integer, _
            ByVal wParam As Integer, _
            ByRef lParam As KBDLLHOOKSTRUCT) As Integer
 
            If (nCode = HC_ACTION) Then
                Select Case wParam
                    Case WM_KEYDOWN
                        Select Case lParam.vkCode
                            Case Keys.F1 To Keys.F7
                                Return True ' Suppress WM_KEYDOWN
 
                        End Select
 
                    Case WM_KEYUP
                        Select Case lParam.vkCode
                            Case Keys.F1 To Keys.F7
                                ' Make sure the Function key is up:
                                KeyPress(lParam.vkCode, False)
 
                                ' 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
 
                                Select Case lParam.vkCode
                                    Case Keys.F1
                                        ' Ctrl-U
                                        KeyPress(Keys.ControlKey, True)
                                        KeyPress(Keys.U, True)
                                        KeyPress(Keys.U, False)
                                        KeyPress(Keys.Control, False)
 
                                    Case Keys.F2
                                        ' Ctrl-B
                                        KeyPress(Keys.ControlKey, True)
                                        KeyPress(Keys.B, True)
                                        KeyPress(Keys.B, False)
                                        KeyPress(Keys.Control, False)
 
                                    Case Keys.F3
                                        ' Ctrl-F
                                        KeyPress(Keys.ControlKey, True)
                                        KeyPress(Keys.F, True)
                                        KeyPress(Keys.F, False)
                                        KeyPress(Keys.Control, False)
 
                                    Case Keys.F4
                                        ' Ctrl-E
                                        KeyPress(Keys.ControlKey, True)
                                        KeyPress(Keys.E, True)
                                        KeyPress(Keys.E, False)
                                        KeyPress(Keys.Control, False)
 
                                    Case Keys.F5
                                        ' Ctrl-V
                                        KeyPress(Keys.ControlKey, True)
                                        KeyPress(Keys.V, True)
                                        KeyPress(Keys.V, False)
                                        KeyPress(Keys.Control, False)
 
                                        System.Threading.Thread.Sleep(100)
 
                                        ' V
                                        KeyPress(Keys.V, True)
                                        KeyPress(Keys.V, False)
 
                                    Case Keys.F6
                                        ' Ctrl-W
                                        KeyPress(Keys.ControlKey, True)
                                        KeyPress(Keys.W, True)
                                        KeyPress(Keys.W, False)
                                        KeyPress(Keys.Control, False)
 
                                    Case Keys.F7
                                        ' Ctrl-T
                                        KeyPress(Keys.ControlKey, True)
                                        KeyPress(Keys.T, True)
                                        KeyPress(Keys.T, False)
                                        KeyPress(Keys.Control, False)
                                    
                                End Select
 
                                System.Threading.Thread.Sleep(100)
 
                                ' Ctrl-M
                                KeyPress(Keys.ControlKey, True)
                                KeyPress(Keys.M, True)
                                KeyPress(Keys.M, False)
                                KeyPress(Keys.Control, False)
 
                                Return True
 
                        End Select
 
                End Select
            End If
 
            Return CallNextHookEx(hhkLowLevelKeyboard, nCode, wParam, lParam)
        End Function
 
        Private Sub KeyPress(ByVal keyCode As Integer, ByVal DownState As Boolean)
            keybd_event(keyCode, MapVirtualKey(keyCode, 0), IIf(DownState, 0, 2), 0)
        End Sub
 
        Protected Overrides Sub Finalize()
            UnhookWindowsHookEx(hhkLowLevelKeyboard)
            MyBase.Finalize()
        End Sub
 
    End Class
 
End Class
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:

Select allOpen in new window

 

by: mechanismPosted on 2009-10-25 at 16:29:48ID: 25659013

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

 

by: mechanismPosted on 2009-10-29 at 05:40:35ID: 25692925

Sorry for delay, I think the autonomous solution is what I was looking for.

Thank you all



Nick

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...