c# - Check Keyboard Input Winforms -


i wondering if instead of doing this

protected override void onkeydown(keyeventargs e) {     if (e.keycode == keys.a)         console.writeline("the key down."); } 

i set bool method , this:

if(keydown(keys.a)) // whatever here 

i've been sitting here ages trying figure out how it. can't wrap head around it.

in case wondering, plan call bool inside different method, check input.

since want perform action after pressing key, using keydown event enough.

but in cases suppose want check if specific key down in middle of process, can use getkeystate method way:

[dllimport("user32.dll", charset = charset.auto, exactspelling = true)] public static extern short getkeystate(int keycode); public const int key_pressed = 0x8000; public static bool iskeydown(keys key) {     return convert.toboolean(getkeystate((int)key) & key_pressed); } 

you should know, each time check key state using example iskeydown(keys.a) method returns true if key pressed @ moment of checking state.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -