Solved

Detecting a key combination from any other application.

Posted on 1999-01-21
2
147 Views
Last Modified: 2010-05-03
I would like to be able to detect a key combination such as Crtl+G (or a single key for that matter) from my application when the key(s) are pressed in any other application.  Once the key(s) have been detected I would then like to copy some text to the other application (probably using sendkeys or the clipboard).  Any one have any ideas on how to detect the keyboard input?

Thanks in advance

~Ian
0
Comment
Question by:iankosh
2 Comments
 
LVL 3

Accepted Solution

by:
covington earned 200 total points
Comment Utility
Use the GetAsyncKeyState API.

Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Const VK_CONTROL = &H11

You pass in VK_CONTROL and ASC("G") in succession like this:

    Do
        If (GetAsyncKeyState(VK_CONTROL)) Then
            If (GetAsyncKeyState(ASC("G"))) Then  
            'do your stuff here
            End If
        DoEvents
        Sleep 25    'this app does not even register 1% of processor time on most machines
                    'even though it's checking 40 times a second for keyboard events
    Loop

Make sure you include some way for breaking out of that loop so that you release the memory when you're done.
0
 

Author Comment

by:iankosh
Comment Utility
Thanks very much! (Easy when you know the API call!!!)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 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

11 Experts available now in Live!

Get 1:1 Help Now