Solved

Trigger double key CTRL key press in Windows C#

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Phone number for Microsoft server activation issues 3 52
Numerous files can not be opened anymore 17 63
Problem to file 3 67
Visual Studio: built-in keystroke automation 2 49
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now