Solved

how to trigger function by keypressed

Posted on 2006-10-31
8
212 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 20 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS 2016 Rendering HTML tables 3 85
Convert Ctime to date time in textfile? 7 81
Broken .resx file generating errors 18 40
Make borderless form movable by user 2 25
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 …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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