View Full Version : A Question?!?!
CiNiMoDZA
19-11-2009, 05:20 PM
How does a keyboard(or any hardware for that matter) tell the computer how to respond? I have not studied so I dont know? How I have it in my head is this:
KEYBOARD PRESS-----DLL-----PROGRAM
The user presses something on their keyboard and the dll then tells the program what to do! Its the only way I can think of how it works! Please correct me if I am wrong!
Fengol
19-11-2009, 05:55 PM
http://en.wikipedia.org/wiki/Operating_system#Features
"The operating system acts as an interface between an application and the hardware. The user interacts with the hardware from "the other side". The operating system is a set of services which simplifies development of applications. Executing a program involves the creation of a process by the operating system. The kernel creates a process by assigning memory and other resources, establishing a priority for the process (in multi-tasking systems), loading program code into memory, and executing the program. The program then interacts with the user and/or other devices and performs its intended function."
Look up operating systems and interrupts
Chippit
19-11-2009, 05:56 PM
Short answer:
Your operating system handles it.
Long answer:
In a bit of a simplified explanation - every keypress on your keyboard generates what is known as a hardware interrupt which tells the CPU to stop doing what it's doing and call the interrupt handler associated with that particular interrupt. This can be a device driver or something, but in this case it'll be a section in the kernel of your operating system that will figure out (based on your keyboard layout settings and whatever), which key you've pressed.
The OS subsequently decides which programs need to know about this keypress (because it doesn't usually send it to all of them, and some keypresses or combination events, like Ctrl-Alt-Del in Windows, never get sent to application programs at all) and sends them a message telling them that a certain key has been pressed. At which point the program decides how (and if) it should respond.
As is typical in computer science, nothing is actually as basic as it appears to be to the user.
EDIT:
******* you, Fengol. :( You made me type that all up for nothing.
Fengol
19-11-2009, 06:39 PM
So for real, real not for play, play I was in hospital on Tues and Weds because I've been having chest pains and dizzy spells and they put me through a whole bunch of tests including heart sonar and x-ray.
What they found was a lump of coal encased in ice and seeping in pure evil.
*Evil laugh*
CiNiMoDZA
19-11-2009, 09:59 PM
Ok, but then how do I emulate a key press. Im using C#. When I use Sendkeys.Send() some programs dont pick this up!
Chippit
19-11-2009, 11:02 PM
You'll probably need to use P/Invoke to call some or other Win32 API function for that. I doubt it's part of the standard .NET functionality.
Necrolis
20-11-2009, 07:57 AM
dunno about C#, but on WinAPI the functions for sending key messages are:
keybd_event (http://msdn.microsoft.com/en-us/library/ms646304%28VS.85%29.aspx)(this has been superseeded by SendInput, but its still works fine if you don't want to bother with SendInput, there is C# syntax at the bottom of the page as well)
SendInput (http://msdn.microsoft.com/en-us/library/ms646310%28VS.85%29.aspx)
dislekcia
20-11-2009, 11:44 AM
Ok, but then how do I emulate a key press. Im using C#. When I use Sendkeys.Send() some programs dont pick this up!
Let me guess: The programs that aren't registering inputs this way are games?
Some games poll input at a lower level than OS event handling, so you're going to need to look for a way to inject interrupts directly. I have no idea how to do this on Windows. In DOS you'd spoof an interrupt with assembler and jump directly the the input handling table.
CiNiMoDZA
20-11-2009, 02:29 PM
Haha, well what I did to test if it was sending was use a keylogger! Now the first keylogger I used didnt pick up the "fake" presses but some others did! Why?? Could you explain it in a simple way :D
dislekcia
20-11-2009, 03:05 PM
Haha, well what I did to test if it was sending was use a keylogger! Now the first keylogger I used didnt pick up the "fake" presses but some others did! Why?? Could you explain it in a simple way :D
Different methods of catching keypresses.
Think of it as a train track. At the start of the track is your CPU (yup, not your keyboard), the track goes out to your keyboard via the motherboard and loops back to the CPU as it "asks" the keyboard if anything is pressed. Then the track heads into software space and goes through the driver station, the OS station, the Windows API suburbs, the event handling and message passing cities and eventually into a specific software application.
The sending process you're using injects "fake" train cars at a specific point along that track. Some of the keyloggers are "spying" on that track in completely different locations, those that are looking earlier on the track (closer to the hardware) than your insertion point won't see your fake train cars. It's as simple as that :)
Necrolis
20-11-2009, 05:58 PM
Let me guess: The programs that aren't registering inputs this way are games?
Some games poll input at a lower level than OS event handling, so you're going to need to look for a way to inject interrupts directly. I have no idea how to do this on Windows. In DOS you'd spoof an interrupt with assembler and jump directly the the input handling table.Using the WinAPI functions you can get games that use things like DInput etc to recieve spoofed keystrokes, so unless someone went and made some really special input handling for thier game, you shouldn't have problems that would require the use of asm(though if they did create something funky, a bit of debugging and a typedef'ed call will get you the same effect as the WinAPI funcs :P)
CiNiMoDZA
21-11-2009, 09:25 AM
Ok, but Im not doing this for myself! I wanna figure out how to make my own "WinAPI". Now back to Dislekia's post! how do I put my train cars in from the beginning :P
P.S I tried Google-ing inserting train cars earlier, but I didnt learn much!!
CiNiMoDZA
01-12-2009, 05:37 PM
+1 For Google:
SendKeys.Flush():
Processes all the Windows messages currently in the message queue.
Ta Da!! She works :D
AndrewJ
03-12-2009, 03:01 PM
Ok, but Im not doing this for myself! I wanna figure out how to make my own "WinAPI".Excuse me?
Excuse me?
Perhaps his own Api that builds onto the WinAPI (same functionality, but easier to use) to do the same tasks but wraps various elements that have to be used together into easy to use functions?
Like a wrapper that makes does this sending of keyboard commands in one line, eg: myapi.kb.sendkey(10);
Ive dont similar stuff for some of the things Ive been busy with lately and its really made my code more readable and also made it more fun to program. Thankfully I havent had to do this too much though, it could get tedious writing hundreds of wrappers.
AndrewJ
09-12-2009, 11:44 AM
Oh, ok, so he wants to build his own mini(?) framework. Just what I understood it from the way it was phrased was... well, an unpleasant prospect.
CiNiMoDZA
09-12-2009, 01:56 PM
Well, no! But what I needed to do I couldn't use winApi! Ill show you guys soon enough! Im setting up some appointments but as soon as I can, Ill tell you guys :D
Powered by vBulletin® Version 4.2.4 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.