getasynckeystate

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.
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
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?
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
The example I gave isn't complete. I just wanted to give you an idea...
Topic archived. No new replies allowed.