Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

i'm a beginner/novice to programming.
i like programming but it seems that programming does not run in my blood :P

I know there's are a lot of articles regarding keystrokes here but i wanted to ask for help for a certain app im working on, a simple win32 EXE file. probably written in C but i dont know how to start?

i want to send a keysroke to say, notepad. first i have two programs open, 1.notepad and 2.the app im working on say a form/API as active with a button "send", once send is clicked it will enable the notepad and send say letter "v" to notepad pause for while maybe 3 secs. then sends "SPACE" then pauses again for 3 secs. then send again "v". lets say its a loop. it will only end when i press "end" on the keyboard or "F12".

the notepad will have the values below,

v v v v v v v v v v v v .... until i end the application.

something like that.

I found an article and a sample code below below by Ali, but i was hopping it could be modified to add the pause, once i click on send keystroke using his sample, the letter will go to notepad which i was looking for, but it sends all added keys at once. i wish you could help me add the 3-5 sec delayed before sending the next keys and loop the added keys until i click done or end the keystroke app.

Sending Keystrokes to another Application in C#[^]


Thanks in advance.
Posted
Updated 27-Jan-14 20:59pm
v3

1 solution

The only reliable universal way of sending keystrokes to external application is using the low-level Windows API SendInput:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

—SA
 
Share this answer
 
v3
Comments
pasztorpisti 28-Jan-14 15:50pm    
+5, your statement holds true but most of the time simply sending keyboard/mouse messages to the target window works even if the target window isn't focused/foregrounded. Some applications switch mode as a result of WM_ACTIVATE/WM_ACTIVATEAPP/WM_FOCUS and in those cases posting messages may not work.
Sergey Alexandrovich Kryukov 28-Jan-14 16:02pm    
Thank you. And as you know, some application's controls don't even handle those WM_s (WPF). So, only performance of low-level keystroke, starting from the moment things can be activated/focused, can help...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900