Преглед на файлове

Reset key state when window gains focus

When the window gains focus, reset the up/down state of all keys. Fixes #19.
Bentley James Oakes преди 7 години
родител
ревизия
609798cdb2
променени са 1 файла, в които са добавени 11 реда и са изтрити 0 реда
  1. 11 0
      client/window_event.js

+ 11 - 0
client/window_event.js

@@ -211,6 +211,16 @@ WindowEventHelper = function(){
 	this.isKeyPressed = function( keyCode ){
 		return currentKeys[ keyCode ] == 1;
 	};
+
+	/**
+	 * Called when the window gains focus
+	 * Resets all keys
+	 */
+	this.onfocus = function(){
+		for (let keyCode in currentKeys){
+			currentKeys[ keyCode ] = 0;
+		}
+	};
 	
 	/**
 	 * Initializes the default window behavior
@@ -223,6 +233,7 @@ WindowEventHelper = function(){
 		window.onmousemove = this.onMouseMove;
 		window.onkeydown = this.onKeyDown;
 		window.onkeyup = this.onKeyUp;
+		window.onfocus = this.onfocus;
 	};
 	
 	return this;