Toggle state in c# - wpf -


i want make function work in toggle(switch) mode when press key , can't figure how it. tried lots of ways , "registerhotkey" method working fine. "registerhotkey" overwriting mapped key game , not need. i'm trying use "getkeystate". code below it's working 1 position no matter change...:

private void mw_keydown(object sender, keyeventargs e){     bool sw = (toggle = !toggle);     int tog = (getkeystate(key.tab));       if ((tog & 1) == 1)     {        if (sw)        {             system.windows.messagebox.show("go second position...!");        }     }     else     {         system.windows.messagebox.show("go first position...!");     } } 

any idea or suggestion how can ?

thank you,

solution provided sergey alexandrovich kryukov codeproject.

link: solution

public partial class mainwindow : window {      bool toggle;      public mainwindow()     {         initializecomponent();         mainwindow.keydown += (sender, eventargs) => { if (eventargs.key == key.f7) toggle = !toggle; };     }      private void mainwindow_keydown(object sender, eventargs e)     {          if (toggle)         {             //system.windows.messagebox.show("go second position...!");         }         else         {             //system.windows.messagebox.show("go first position...!");         }     } } 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo