From: Holger Z. <hz...@us...> - 2005-06-07 08:43:54
|
Update of /cvsroot/jake2/jake2/src/jake2/sys In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14136/src/jake2/sys Modified Files: LWJGLKBD.java Log Message: simulate keyboard repeats Index: LWJGLKBD.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/sys/LWJGLKBD.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** LWJGLKBD.java 20 Feb 2005 13:55:26 -0000 1.8 --- LWJGLKBD.java 7 Jun 2005 08:43:43 -0000 1.9 *************** *** 2,5 **** --- 2,6 ---- import jake2.Defines; + import jake2.Globals; import jake2.client.Key; import jake2.qcommon.Cbuf; *************** *** 15,18 **** --- 16,20 ---- private char[] lwjglKeycodeMap = null; + private int pressed[] = null; private boolean mouseHasTwoButtons = false; *************** *** 30,36 **** --- 32,40 ---- if (lwjglKeycodeMap == null) lwjglKeycodeMap = new char[256]; + if (pressed == null) pressed = new int[256]; mouseHasTwoButtons = (Mouse.getButtonCount() == 2); + lastRepeat = Sys.Milliseconds(); } catch (Exception e) {;} } *************** *** 46,49 **** --- 50,54 ---- // free the memory for GC lwjglKeycodeMap = null; + pressed = null; } *************** *** 66,74 **** // this is needed because the getEventCharacter() returns \0 if a key is released // keycode is correct but the charachter value is not ! if (down) lwjglKeycodeMap[key] = ch; ! Do_Key_Event(XLateKey(key,ch), down); } if (IN.mouse_active) { --- 71,86 ---- // this is needed because the getEventCharacter() returns \0 if a key is released // keycode is correct but the charachter value is not ! if (down) { ! lwjglKeycodeMap[key] = ch; ! pressed[key] = Globals.sys_frame_time; ! } else { ! pressed[key] = 0; ! } ! Do_Key_Event(XLateKey(key,ch), down); } + generateRepeats(); + if (IN.mouse_active) { *************** *** 99,102 **** --- 111,126 ---- } + private static int lastRepeat; + private void generateRepeats() { + int time = Globals.sys_frame_time; + if (time - lastRepeat > 50) { + for (int i = 0; i < pressed.length; i++) { + if (pressed[i] > 0 && time - pressed[i] > 500) + Do_Key_Event(XLateKey(i, lwjglKeycodeMap[i]), true); + } + lastRepeat = time; + } + } + private int XLateKey(int code, int ch) { |