Solved

Trigger double key CTRL key press in Windows C#

Posted on 2013-01-22
2
1,166 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
Comment Utility
You could put a small pause in-between the keystrokes:

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

Author Closing Comment

by:kkrishi
Comment Utility
Thanks, that did the trick
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

763 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

10 Experts available now in Live!

Get 1:1 Help Now