Solved

Application wide Hotkey

Posted on 2009-05-04
2
541 Views
Last Modified: 2012-05-06
Hi experts,

We have developed an application which is in SDI form and has multiple Forms using VB 2005 with .net framework 2.0. We need to provide hotkeys to perform specific actions. This hotkey may be pressed in any of the forms throughout the application. The system should be able to recognize this key press is required to execute some code.

In the above context i have done some research and got a solution which is very close to the one which i require -
www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_21584180.html

The limitation in the solution above is that it works system wide. When my application is minimized and user presses the hotkey, my application still responds to that, which is NOT required.

How can this be achieved?

The hotkey we are trying to use are all the function keys and other keys in combination with CTRL key.

Ketan.

0
Comment
Question by:s_monani
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 24295661
If you want a "HotKey" across all forms, but ONLY in the application, then use IMessageFilter:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.application.addmessagefilter.aspx

Simple example that traps Ctrl-F1, Ctrl-F2, and Ctrl-F3:
Public Class Form1
 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Application.AddMessageFilter(New MyMessageFilter)

    End Sub
 

    Public Class MyMessageFilter

        Implements IMessageFilter
 

        Private Const WM_KEYDOWN As Integer = &H100
 

        Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements IMessageFilter.PreFilterMessage

            Select Case m.Msg

                Case WM_KEYDOWN ' (Check for Ctrl being down...w/o the Alt key down)

                    If My.Computer.Keyboard.CtrlKeyDown AndAlso (Not My.Computer.Keyboard.AltKeyDown) Then

                        Select Case m.WParam.ToInt32

                            Case Keys.F1

                                MessageBox.Show("Ctrl-F1")

                                Return True
 

                            Case Keys.F2

                                MessageBox.Show("Ctrl-F2")

                                Return True
 

                            Case Keys.F3

                                MessageBox.Show("Ctrl-F3")

                                Return True
 

                            ' etc...
 

                        End Select

                    End If
 

            End Select
 

            Return False

        End Function

    End Class
 

End Class

Open in new window

0
 
LVL 1

Author Closing Comment

by:s_monani
ID: 31577463
Thanks a lot, the code exactly what i needed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with sorting data in Listbox using VB.NET 3 53
C# Offline Apllication 5 54
Change Format on Data when exporting to Excel 4 23
Connection String 16 43
IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now