c# - Using of left/right keyboard button -


i'm trying call function left , right buttons on keyboard, not sure how proper way.

in result of attempt, pressing on left/right keyboard keys switches between gui elements usual way, , not works given functions. not sure wrong here:

   private void form1_keydown(object sender, keyeventargs e)    {        if (e.keycode == keys.right)        {           func1();        }        else if (e.keycode == keys.left)        {           func2();        }    } 

an alternative enabling keypreview mentioned in comments override processcmdkey method.

protected override bool processcmdkey(ref message msg, keys keydata)  {     if (keydata == keys.right)     {       func1();       return true;     }     else if (keydata == keys.left)     {       func2();       return true;     }     return base.processcmdkey(ref msg, keydata); } 

please see this msdn article more information.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -