?
Solved

how to trigger function by keypressed

Posted on 2006-10-31
8
Medium Priority
?
217 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

765 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