Solved

Trigger double key CTRL key press in Windows C#

Posted on 2013-01-22
2
1,202 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

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

749 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