Hello and thanks in advance for any help. I am currently trying to write a bit of code that simulates a keystroke via stuffing a scan code directly into the keyboard controller chip and have it return that scan code as though someone actually pressed that key.

To be honest, I am a complete virgin when it comes to assembly and I have no idea what I'm doing. This is a bit more complicated than anything i can comprehend with my limited knowledge, and I'm requesting some more seasoned hands to help me out. The rest of my program is in C#, and I am currently unaware of any way to produce the same effect with it.

Note: I want to write directly to the keyboards buffer, so that the application in focus will not be able to tell the difference between the code and an actual key press. I do not want to use SendInput() or keybd_event or anything like that in C# because the program I'm trying to manipulate can tell the difference and blocks them.

This is the code I have made up so far.

;Return scan code command
mov     al, 0d2h
out     64h, al

; Send the scan code:
mov     al, 20h     ;"D" down scan code
out     60h, al

;Return scan code command
mov     al, 0d2h
out     64h, al

; Send the scan code:
mov     al, 0a0h     ;"D" up scan code
out     60h, al

I figured out that i need to send a 0D2h byte to the controller command port (64h), telling it that the next information it recieves is a scan code, and then follow up by sending the actual scan code byte to port 60h.

I found a similar code here: http://www.programmersheaven.com/mb/x86_asm/332275/332275/simulate-key-press-from-keyboard/?S=B20000
but still don't understand what I'm doing.

I am using Flat Assembler at the moment, and don't genuinely know whether its a decent assembly compiler or not. When I try to compile it, I get a .BIN file and have no idea whether it worked or not. I would like to create a .exe so that when executed, would simulate a specific key press (IE the Tab button) so that I can just call that executable from my main program when needed.

Any observations or suggestions would be greatly appreciated, but try to be detailed. :icon_cheesygrin:

I know this probably really isn't any help to you, but it just might be....
Here is a link to an assembly book that has been very helpful to me (you will be able to look in the index to hopefully find the answer to your question)...

http://books.google.com/books?id=9Pe6Ajhn40sC&printsec=frontcover&dq=assembly+irvine&source=bl&ots=ESsKsvzpzq&sig=tHREu0XH_IzVacJPcEzJOmG_BrI&hl=en&ei=9HepS4DNEofUMsbNnZkB&sa=X&oi=book_result&ct=result&resnum=5&ved=0CCUQ6AEwBA#v=onepage&q=&f=false

I also use Microsoft Visual Studio to link/compile/run my assembly programs.

I'm hoping this was at least a tad bit helpful ;)

Thanks for the reply amylyn, I'll try driving past barnes and noble tomorrow and seeing if i can find anything interesting :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.