From 68835ec642a841c1ec1a7aca4cf76939deb71eb0 Mon Sep 17 00:00:00 2001 From: Eric Myllyoja Date: Fri, 8 Jul 2022 22:10:02 -0400 Subject: [PATCH] Added timestamp to KeyDown and KeyUp events. --- project/include/ui/KeyEvent.h | 1 + project/src/backend/sdl/SDLApplication.cpp | 1 + project/src/ui/KeyEvent.cpp | 5 +++++ src/lime/_internal/backend/html5/HTML5Application.hx | 5 +++-- .../_internal/backend/native/NativeApplication.hx | 11 +++++++---- src/lime/app/Application.hx | 6 ++++-- src/lime/ui/Window.hx | 4 ++-- 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/project/include/ui/KeyEvent.h b/project/include/ui/KeyEvent.h index 28e6fcc6fd..803a6290a9 100644 --- a/project/include/ui/KeyEvent.h +++ b/project/include/ui/KeyEvent.h @@ -25,6 +25,7 @@ namespace lime { int modifier; KeyEventType type; int windowID; + int timestamp; static ValuePointer* callback; static ValuePointer* eventObject; diff --git a/project/src/backend/sdl/SDLApplication.cpp b/project/src/backend/sdl/SDLApplication.cpp index 07b7e81fd9..9187d49d72 100644 --- a/project/src/backend/sdl/SDLApplication.cpp +++ b/project/src/backend/sdl/SDLApplication.cpp @@ -575,6 +575,7 @@ namespace lime { keyEvent.keyCode = event->key.keysym.sym; keyEvent.modifier = event->key.keysym.mod; keyEvent.windowID = event->key.windowID; + keyEvent.timestamp = event->key.timestamp; if (keyEvent.type == KEY_DOWN) { diff --git a/project/src/ui/KeyEvent.cpp b/project/src/ui/KeyEvent.cpp index 42acd15560..7905c15cfe 100644 --- a/project/src/ui/KeyEvent.cpp +++ b/project/src/ui/KeyEvent.cpp @@ -12,6 +12,7 @@ namespace lime { static int id_modifier; static int id_type; static int id_windowID; + static int id_timestamp; static bool init = false; @@ -21,6 +22,7 @@ namespace lime { modifier = 0; type = KEY_DOWN; windowID = 0; + timestamp = 0; } @@ -37,6 +39,7 @@ namespace lime { id_modifier = val_id ("modifier"); id_type = val_id ("type"); id_windowID = val_id ("windowID"); + id_timestamp = val_id ("timestamp"); init = true; } @@ -47,6 +50,7 @@ namespace lime { alloc_field (object, id_modifier, alloc_int (event->modifier)); alloc_field (object, id_type, alloc_int (event->type)); alloc_field (object, id_windowID, alloc_int (event->windowID)); + alloc_field (object, id_timestamp, alloc_int (event->timestamp)); } else { @@ -56,6 +60,7 @@ namespace lime { eventObject->modifier = event->modifier; eventObject->type = event->type; eventObject->windowID = event->windowID; + eventObject->timestamp = event->timestamp; } diff --git a/src/lime/_internal/backend/html5/HTML5Application.hx b/src/lime/_internal/backend/html5/HTML5Application.hx index 78a4c3bfbe..2fd6052a81 100644 --- a/src/lime/_internal/backend/html5/HTML5Application.hx +++ b/src/lime/_internal/backend/html5/HTML5Application.hx @@ -412,10 +412,11 @@ class HTML5Application var keyCode = cast convertKeyCode(event.keyCode != null ? event.keyCode : event.which); var modifier = (event.shiftKey ? (KeyModifier.SHIFT) : 0) | (event.ctrlKey ? (KeyModifier.CTRL) : 0) | (event.altKey ? (KeyModifier.ALT) : 0) | (event.metaKey ? (KeyModifier.META) : 0); + var timestamp = event.timeStamp; if (event.type == "keydown") { - parent.window.onKeyDown.dispatch(keyCode, modifier); + parent.window.onKeyDown.dispatch(keyCode, modifier, timestamp); if (parent.window.onKeyDown.canceled && event.cancelable) { @@ -424,7 +425,7 @@ class HTML5Application } else { - parent.window.onKeyUp.dispatch(keyCode, modifier); + parent.window.onKeyUp.dispatch(keyCode, modifier, timestamp); if (parent.window.onKeyUp.canceled && event.cancelable) { diff --git a/src/lime/_internal/backend/native/NativeApplication.hx b/src/lime/_internal/backend/native/NativeApplication.hx index af2f38d297..58277822a1 100644 --- a/src/lime/_internal/backend/native/NativeApplication.hx +++ b/src/lime/_internal/backend/native/NativeApplication.hx @@ -257,14 +257,15 @@ class NativeApplication var int32:Float = keyEventInfo.keyCode; var keyCode:KeyCode = Std.int(int32); var modifier:KeyModifier = keyEventInfo.modifier; + var timestamp:Int = keyEventInfo.timestamp; switch (type) { case KEY_DOWN: - window.onKeyDown.dispatch(keyCode, modifier); + window.onKeyDown.dispatch(keyCode, modifier, timestamp); case KEY_UP: - window.onKeyUp.dispatch(keyCode, modifier); + window.onKeyUp.dispatch(keyCode, modifier, timestamp); } #if (windows || linux) @@ -755,18 +756,20 @@ class NativeApplication public var modifier:Int; public var type:KeyEventType; public var windowID:Int; + public var timestamp:Int; - public function new(type:KeyEventType = null, windowID:Int = 0, keyCode: Float = 0, modifier:Int = 0) + public function new(type:KeyEventType = null, windowID:Int = 0, keyCode: Float = 0, modifier:Int = 0, timestamp:Int = 0) { this.type = type; this.windowID = windowID; this.keyCode = keyCode; this.modifier = modifier; + this.timestamp = timestamp; } public function clone():KeyEventInfo { - return new KeyEventInfo(type, windowID, keyCode, modifier); + return new KeyEventInfo(type, windowID, keyCode, modifier, timestamp); } } diff --git a/src/lime/app/Application.hx b/src/lime/app/Application.hx index 0cdf4d3e76..8b80aa833a 100644 --- a/src/lime/app/Application.hx +++ b/src/lime/app/Application.hx @@ -239,15 +239,17 @@ class Application extends Module Called when a key down event is fired on the primary window @param keyCode The code of the key that was pressed @param modifier The modifier of the key that was pressed + @param timestamp A preceise timestamp for the event **/ - public function onKeyDown(keyCode:KeyCode, modifier:KeyModifier):Void {} + public function onKeyDown(keyCode:KeyCode, modifier:KeyModifier, timestamp:Int):Void {} /** Called when a key up event is fired on the primary window @param keyCode The code of the key that was released @param modifier The modifier of the key that was released + @param timestamp A preceise timestamp for the event **/ - public function onKeyUp(keyCode:KeyCode, modifier:KeyModifier):Void {} + public function onKeyUp(keyCode:KeyCode, modifier:KeyModifier, timestamp:Int):Void {} /** Called when the module is exiting diff --git a/src/lime/ui/Window.hx b/src/lime/ui/Window.hx index 1cdc8dd73f..4cbd999399 100644 --- a/src/lime/ui/Window.hx +++ b/src/lime/ui/Window.hx @@ -62,8 +62,8 @@ class Window public var onFocusIn(default, null) = new EventVoid>(); public var onFocusOut(default, null) = new EventVoid>(); public var onFullscreen(default, null) = new EventVoid>(); - public var onKeyDown(default, null) = new EventKeyModifier->Void>(); - public var onKeyUp(default, null) = new EventKeyModifier->Void>(); + public var onKeyDown(default, null) = new EventKeyModifier->Int->Void>(); + public var onKeyUp(default, null) = new EventKeyModifier->Int->Void>(); public var onLeave(default, null) = new EventVoid>(); public var onMaximize(default, null) = new EventVoid>(); public var onMinimize(default, null) = new EventVoid>();