Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trigger double key CTRL key press in Windows C#

Posted on 2013-01-22
2
Medium Priority
?
1,261 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 86

Accepted Solution

by:
Mike Tomlinson earned 1600 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

971 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