[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how to trigger function by keypressed

Posted on 2006-10-31
8
Medium Priority
?
219 Views
Last Modified: 2010-04-23
I gonna pop up the message box everytime i pressed "F12" in my keyboard. ( or i pressed Ctrl + Y")

Private Function testing ()
    Msgbox ("Hello")
End Function

How to do it?
0
Comment
Question by:kengkit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17847574
Do you want this only when YOUR app is in focus?  Or when ANY app is in focus?
0
 

Author Comment

by:kengkit
ID: 17847585
in fact.. i juz wants tis when my app is in focus

but it's good if u can tell me both.
0
 
LVL 17

Expert Comment

by:ZeonFlash
ID: 17847679
I'm not sure how to do it if your app doesn't have focus (I haven't brushed up on my keyboard hooking), but here's how you can do it if your app has focus:

    Private Function testing()
        Msgbox("Hello")
    End Function

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        If keyData = Keys.Control + Keys.Y Or keyData = Keys.F12 Then
            testing()
            Return True
        End If
    End Function
0
 
LVL 6

Expert Comment

by:manch
ID: 17847701
'U Can use the IMessageFilter Interface for it
' Creates a message filter.
Public Class TestMessageFilter
   Implements IMessageFilter

   Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) _
   As Boolean Implements IMessageFilter.PreFilterMessage
      ' Blocks all the messages relating to the left mouse button.
      If ((m.Msg >= 513) And (m.Msg <= 515)) Then
         Console.WriteLine("Processing the messages : " & m.Msg)
         Return True
      End If
      Return False
   End Function
End Class

Try It
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 80 total points
ID: 17847705
Here is an example of the hook approach that allows you trap keypresses while your app is not in focus:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21584180.html
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

649 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