Solved

how to trigger function by keypressed

Posted on 2006-10-31
8
176 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
8 Comments
 
LVL 85

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 85

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

16 Experts available now in Live!

Get 1:1 Help Now