Solved

Detecting a key combination from any other application.

Posted on 1999-01-21
2
151 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
[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
2 Comments
 
LVL 3

Accepted Solution

by:
covington earned 200 total points
ID: 1469806
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
ID: 1469807
Thanks very much! (Easy when you know the API call!!!)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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