Solved

Trigger double key CTRL key press in Windows C#

Posted on 2013-01-22
2
1,190 Views
Last Modified: 2013-01-30
All:
I have an application that starts a job when CTRL key is pressed twice. For a test, i am trying to simulate the keypress from a C# console application so that the main application can process the key strokes and start the job

The issue I am having is if I have the application start the job when a single CTRL key is pressed, it works fine. However if I have the application to start the job when two CTRL keys are pressed, the job does not start (i.e. app does not get the trigger)

I am testing on Windows 8, using the Win32 API keybd_event


Here is the code snippet

        keybd_event(VK_LCONTROL,0x9d,0 , 0);
       keybd_event(VK_LCONTROL,0x9d,KEYEVENTF_KEYUP,0);

       keybd_event(VK_LCONTROL,0x9d,0 , 0);
       keybd_event(VK_LCONTROL,0x9d,KEYEVENTF_KEYUP,0);


I suspect this to be some timing issue... Can any expert point out how i can do this differently?

Thanks!
Karthik K Rishi
0
Comment
Question by:kkrishi
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 400 total points
ID: 38807446
You could put a small pause in-between the keystrokes:

    ...
    System.Threading.Thread.Sleep(250);
    ...
0
 

Author Closing Comment

by:kkrishi
ID: 38837985
Thanks, that did the trick
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

829 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