I have a great idea about cheating on exams. My school uses very old IDE’s ( think Turbo Pascal, Turbo C++ , and other 80’s ones ), and the thing I’d like to do is this :
-
start my program in the background
-
intercept the keypresses, and instead of sending them directly to the screen, I’d like to read a character from a pre-configured text-file, and send that as the pressed key. This way, no matter what you’ll write, the text from that file will get written on the screen.
I found Stephen Toub’s article about logging keys, and I think it will serve as a good start on building this “tool“. Is there a better alternative to intercepting all the keys pressed in the system than SetWindowsHookEx? Will the code be flagged by the antivirus as a suspicious program? If so, is there anything else I can use to accomplish this without being flagged by the antivirus? Will administrator priviledges be required ?
I know some of you guys will say that If I’d put as much interest in learning as I do in avoiding learning, I’d do great, but I’d like to try this out.
EDIT: I’ve added a bounty, I’m interested in some techniques for capturing keystrokes ( I’m not interested in low-level hooking or advanced stuff – basic ones are fine ), mainly method names and some links to documentation. I’d also like to know if they would appear as malware to an antivirus.
GOD! I’ve just found the perfect class for this the other day.. took me a while to find the original source:
http://www.codeproject.com/KB/cs/globalhook.aspx
I used this (and SendKeys) alone exactly for what you need, you’ll need to use Handle=true to block the original key message.
SendKeys is a bit ugly… you can look for a replacement if you’d like.. but SendKeys will work for you.
With SendKeys it’s something like:
I actually also use this method to determined what prccess’ window is in focus, so the app will do nothing if you are on another application: