c# - Keydown Eventhandler Process -
i trying process keydown event below code process first char of string , not able remove second char of string.
private void game_keydown(object sender, keyeventargs e) { if(birdsarray[selectedindex].this_string.first()== (char)e.keydata) { birdsarray[selectedindex].this_string = birdsarray[selectedindex].this_string.remove(0, 1); this.validate(); } }
in below code birdsarray
array of panels, this_string
string type of string object in birdsarray
.
the keydown event gives virtual key code of key pressed. keys.a if press a-key. tells key, not letter that's produced key. depends on active keyboard layout (it not in japan or russia example) , modifier keys down. shift being obvious example, producing either a
or a
. or alt which, when down, doesn't produce letter @ all.
so code work accident if first letter of string capitalized. you'll run out of luck when rest not. a
not match a
.
it pretty unclear me why need feature. consider keypress event instead. gives actual letter user sees on screen.
Comments
Post a Comment