getasynckeystate
Oct 3, 2012 at 10:13pm UTC
hi,
how can i toggle the same key to turn on and off
1 2 3 4 5 6 7 8 9
if (GetAsyncKeyState(VK_F1)/*code here to turn ON*/ )
{
cout << "ON" << endl;
}
if (GetAsyncKeyState(VK_F1)/*code here to turn OFF*/ )
{
cout << "OFF" << endl;
}
thanks in advance.
Oct 3, 2012 at 10:45pm UTC
Maybe having a global variable or local, say...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int x=0; //off state
GetAsyncKeyState(VK_F1)
{
if (x==0)/*code here to turn ON*/
{
cout << "ON" << endl;
x=1; //on
}
else if (x==1)/*code here to turn OFF*/
{
cout<<"OFF" ;
x=0; //off
}
}
Hope it HELPS!!!
Last edited on Oct 3, 2012 at 10:46pm UTC
Oct 4, 2012 at 2:13am UTC
1 2 3 4 5 6 7 8 9 10
int x=0; //off state
Bool GetAsyncKeyState(VK_F1)
{
x=1-x
cout << " Toggle " << x << endl;
return x
}
Maybe this?
Oct 4, 2012 at 2:50am UTC
i got error on both..but thanks
actually i already have this code i just lost it thou..i remember it has something to do with.. 0x8000 (to turn on)...or -37628 (to turn off)...something like that..i tried it but failed
Oct 4, 2012 at 6:06am UTC
The example I gave isn't complete. I just wanted to give you an idea...
Topic archived. No new replies allowed.