Registering when [SHIFT] is pressed/released

hi everyone! just started learning c++ a few days ago and have already written 3 or so small programs but i cant seem to find a way around this issue...
basically i want my program to output/register when the user presses something (so it would output [SHIFTon] for example) and then also registers/outputs something when they eventually release the key (so it would then output [SHIFToff])
ive looked around this website along with some other places trying to find a solution for this but either i cant find what im looking for or the solution i find doesn't work/i have no idea how to properly use it.
so does anyone here have any tips or ideas for workign around this? thanks in advance!
C++ is a bare bones language. There is no standard library for getting keyboard events because the program might not be running with a keyboard (i.e. a robot.) Therefor you need to find a third-party library to do this (and their code will use OS functions to do what you need, like for example the Windows API, but don't do that yourself, it's confusing for someone new to programming.)
Last edited on
14 & 15 in the ascii table?

http://www.asciitable.com/
tried that, doesn't work :\ first thing i tried actually lol
closed account (zb0S216C)
Usually, you would use the Windows API for such a thing (if you're on Windows). But since your a beginner, I would definitely recommend that you stay away from there.

Don't try and imitate a Win32 application in a console because it just won't work; well, it might, but not that well.

Wazzak
If you do want to try it, you may want to have a look at:
http://msdn.microsoft.com/en-us/library/ms646301%28VS.85%29.aspx

I don't have time to play with it at the moment, but it seems to toggle, don't know if you can stop that and use a 'held down' state or something similar:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>		// cout
#include <Windows.h>	//GetKeyState()


int main()
{
	do
	{
		if( GetKeyState( VK_SHIFT ) )
			std::cout << "Shift down\n";
		else
			std::cout << "Shift up\n";
	
	}while( true );
	

	return 0;
}


Hold CTRL and press C, to terminate the console app. Just in case you didn't know. (:
Last edited on
ok thanks ill take a look at the link you posted aswell as try the code later tonight when i get a chance. and fyi i am on windows and im using visual 2010 express (idk if the compiler matters for this particualr problem but cant hurt to know right?) sorry i shouldve said that before.
also im workign with (GetAsyncKeyState(VK_SHIFT) == -32767) right now to register when shift is pressed and all aswell as other keys
(im tryign to make a keylogger btw, not for malicious purposes obviously but to keep my annoying friends from messing with my computer while im away from it -_-)
Topic archived. No new replies allowed.