events - Lower Keyboard sensitivity in java keyhandler? -
private class keyhandler implements keyeventdispatcher{ @override public boolean dispatchkeyevent(keyevent e) { if(e.getkeycode() == keyevent.vk_right){ tetrominolist.get(currentpiece).moveright(); }else if(e.getkeycode() == keyevent.vk_left){ tetrominolist.get(currentpiece).moveleft(); }else if (e.getkeycode() == keyevent.vk_up){ system.out.print("k"); tetrominolist.get(currentpiece).rotate(); } return false; }
this code returns "kk" when press arrow once. how can configure java or computer register 1 key hit instead of two?
edit: temporary solution
private class keyhandler implements keyeventdispatcher{ int counter = 0; public boolean dispatchkeyevent(keyevent e) { if(e.getkeycode() == keyevent.vk_right){ tetrominolist.get(currentpiece).moveright(); }else if(e.getkeycode() == keyevent.vk_left){ tetrominolist.get(currentpiece).moveleft(); }else if (e.getkeycode() == keyevent.vk_up){ counter++; if(counter == 2){ system.out.print("k"); tetrominolist.get(currentpiece).rotate(); counter = 0; } }
i may wrong looks code processes both key_pressed
, key_released
events. should check key_typed
event , once happens print letter. otherwise can process 1 of first 2 events.
Comments
Post a Comment