Revision: 4045
          http://vexi.svn.sourceforge.net/vexi/?rev=4045&view=rev
Author:   clrg
Date:     2011-03-01 01:41:33 +0000 (Tue, 01 Mar 2011)

Log Message:
-----------
Fix keypresses getting queued up when holding down a key
(respect keyrelease at the expense of matching OS auto-repeat)

Modified Paths:
--------------
    trunk/org.vexi-core.main/src/main/java/org/vexi/core/Surface.java

Modified: trunk/org.vexi-core.main/src/main/java/org/vexi/core/Surface.java
===================================================================
--- trunk/org.vexi-core.main/src/main/java/org/vexi/core/Surface.java   
2011-02-24 03:19:13 UTC (rev 4044)
+++ trunk/org.vexi-core.main/src/main/java/org/vexi/core/Surface.java   
2011-03-01 01:41:33 UTC (rev 4045)
@@ -174,8 +174,26 @@
 
     // Event Handling Helper methods for subclasses ///////////////////
     
-    protected final void KeyPressed(String key) { message(SC_KeyPressed, 
SC__KeyPressed, JSU.S(key), true); }
-    protected final void KeyReleased(String key) { message(SC_KeyReleased, 
SC__KeyReleased, JSU.S(key), true); }
+    private boolean keypress_scheduled = false;
+    protected final void KeyPressed(String key) {
+        // check that we've not already got a keypress active
+        // otherwise the application may 'queue up' keypresses
+        // when the user holds down a key and continue to execute
+        // them after the user has released the key
+        // FIXME: try to respect the OS-setting for auto-repeat
+        // keypresses on a held key; count and auto-reschedule
+        // (but it isn't quite so simple - think about it!)
+        if (!keypress_scheduled) {
+            keypress_scheduled = true;
+            message(SC_KeyPressed, SC__KeyPressed, JSU.S(key), true);
+        }
+    }
+    protected final void KeyReleased(String key) {
+        // force Vexi to respect the number of actual keypresses
+        // just in case the application is slow to respond
+        keypress_scheduled = false;
+        message(SC_KeyReleased, SC__KeyReleased, JSU.S(key), true);
+    }
     protected final void Close() { message(SC_Close, JSU.T); }
     protected final void Minimized(boolean b) { minimized = b; 
message(SC_Minimized, b ? JSU.T : JSU.F); }
     protected final void Maximized(boolean b) { maximized = b; 
message(SC_Maximized, b ? JSU.T : JSU.F); }
@@ -184,6 +202,7 @@
             // REMARK need to unset these here because it becomes
             // tough to detect whether they are still true when a
             // surface becomes refocused - better safe than wrong
+            // (safe being 'false' so a user must repress/click)
             alt = control = shift = false;
             button1 = button2 = button3 = false;
         }
@@ -327,7 +346,7 @@
 
     // Event Message Handlers /////////////////////////////////
     
-    /** event message recycler */
+    /** Mechanism for queueing the processing of an event */
     private void message(JS event, JS value) { message(event, null, value, 
false); }
     private void message(JS event, JS _event, JS value) { message(event, 
_event, value, false); }
     private void message(JS event, JS _event, JS value, boolean forceOnRoot) {
@@ -376,6 +395,7 @@
                     Platform.clipboardReadEnabled = true;
                 }
                 this.value = JSU.S(value);
+                surface.keypress_scheduled = false;
             }
             
             // allow clipboard access if pressing middle mouse button


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to