didn't work the way I wanted it to... I mean it was great, but i want to run this program as a service, so if i switch windows (if one window closes to reveal another window -mabey 2 different levels, i dont know-) the input prcess follows (aka, i dont have to recode the keys).
As I mentioned GetASyncKeyState is nonblocking -- it immediately gives you the realtime state of that key. So if you are checking it in a loop and echoing the keypress to cout, it will spit out a bunch of As as long as the key is held down.
So the question is... what kind of behavior are you looking for?
i did this so I could open the file afterwards and see what I get (because like I said, the way I'm designing this is to run in the background) and the results so far aren't promising. I keep getting the alphabet printed a million times over in a text file... this indicates to me that it isnt recognizing a key has been pressed, just that the key... well.. is a key, i guess...
After i figure this out, it wont write to a text file, but instead be used as input like "move" or "jump" or even be used to store you set options in the option menu.
well... thats odd, it's spitting sh*t out even if a key isn't held...
Okay you're obviously making a keylogger. Async Keystate will work fine, there are better methods but this is where my help ends. (I'm not being high and mighty, just saying if you want to go this route you should have the capability to do it without hand holding)
look, im a BEGINNER. Even if i succeeded in making a keylogger, i wouldn't know how to use it. The only thing i know is that I need this thing to get a key ONCE, and then respond with an action (which might be jump, or move, or mabey a shortcut to a command) that will corralate to my "game". Since you think im making a keylogger, ill tell you my exact plans:
this background program will write a key pressed to a text file, the game will read the text file, store the key as a variable, link the variable "key" with a command (ex: press w to jump) and do an action. But first, I need the darn thing to write to the text file. This is the easiest command structure I can think of to create a game so that commands stay the same, but are carried on throughout the program even if it closes and opens a graphics window where the code may change.
also, if i was making a keylogger, i wouldn't want to sneak around would i? No, i would want the log to be sent at a time from their computer to mine via internet or whatever. Since i don't know jack about networking with C++, you can rest assure if im keylogging, it wont be real.. well... threatening.
The code you posted should be flooding the file with all characters regardless of what keys are held down. Don't put a semicolon after your if statements.
Also, if you find yourself copy/pasting code en-masse like that, you're doing it wrong. You don't need to duplicate code for each key. Put it in a loop:
Converts every character in the string it is passed to lower case. Also, might want to plop that code in a function to keep your main nice and clean. You can make it inline so you don't lose any performance when it's being called frequently.
You will need to create a simple key logger to check each key only once. You can do this with array of bools. Each bool will store if each key has already been pressed. If it has then don't output to the file.