
-----------------------------------
mirhagk
Thu Mar 25, 2010 9:49 am

Sending KeyStrokes to another Application
-----------------------------------
Hello everyone, it's been a while since I've been here, mostly because it's been a while since I used Turing, and the dummies book for C++ was good enough for me.... until now.

Basically what I'm trying to do is create a program that enters keystrokes into other applications (for instance notepad). It is not really something I need, more of a curiousity, and I will probably create an auto-typer just for fun. Can someone please help me, I'm using visual express C++ and I don't want to use the .NET framework unless I ABSOLUTELY have to (school computers don't support it).

Another curiousity is how to check if a key is pressed into any application (ie don't need the window active in order for it to detect keys).

I would very much appreciate any help you have for me.

-----------------------------------
TheGuardian001
Thu Mar 25, 2010 12:32 pm

Re: Sending KeyStrokes to another Application
-----------------------------------
Well, provided that you only intend to develop this for Windows, you can use the either the [url=http://msdn.microsoft.com/en-us/library/ms646304%28VS.85%29.aspx]keybd_event function, or the [url=http://msdn.microsoft.com/en-us/library/ms646310%28VS.85%29.aspx]SendInput function, which supersedes keybd_event.

I'm not sure how you would go about specifying what window to send the input to though...

-----------------------------------
md
Thu Mar 25, 2010 1:47 pm

RE:Sending KeyStrokes to another Application
-----------------------------------
Look into the Win32 API, or what used to be called OLE.

Alas, I do not recall how to do either thing.

-----------------------------------
DemonWasp
Thu Mar 25, 2010 3:41 pm

RE:Sending KeyStrokes to another Application
-----------------------------------
You could try looking at the source of [url=http://www.autohotkey.com/]AutoHotKey if you're stuck; it does pretty much what you describe (picks up keystrokes, changes them before they get to the application, even the selected application).

-----------------------------------
mirhagk
Fri Mar 26, 2010 10:13 am

RE:Sending KeyStrokes to another Application
-----------------------------------
alright i'm looking at the send input right now, I'm still unsure of exactly how it works, but I'll fool around for a bit and *hopefully* get it.
