Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added timestamp to KeyDown and KeyUp events. #1561

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions project/include/ui/KeyEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace lime {
int modifier;
KeyEventType type;
int windowID;
int timestamp;

static ValuePointer* callback;
static ValuePointer* eventObject;
Expand Down
1 change: 1 addition & 0 deletions project/src/backend/sdl/SDLApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
5 changes: 5 additions & 0 deletions project/src/ui/KeyEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand All @@ -21,6 +22,7 @@ namespace lime {
modifier = 0;
type = KEY_DOWN;
windowID = 0;
timestamp = 0;

}

Expand All @@ -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;

}
Expand All @@ -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 {

Expand All @@ -56,6 +60,7 @@ namespace lime {
eventObject->modifier = event->modifier;
eventObject->type = event->type;
eventObject->windowID = event->windowID;
eventObject->timestamp = event->timestamp;

}

Expand Down
5 changes: 3 additions & 2 deletions src/lime/_internal/backend/html5/HTML5Application.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
11 changes: 7 additions & 4 deletions src/lime/_internal/backend/native/NativeApplication.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/lime/app/Application.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/lime/ui/Window.hx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class Window
public var onFocusIn(default, null) = new Event<Void->Void>();
public var onFocusOut(default, null) = new Event<Void->Void>();
public var onFullscreen(default, null) = new Event<Void->Void>();
public var onKeyDown(default, null) = new Event<KeyCode->KeyModifier->Void>();
public var onKeyUp(default, null) = new Event<KeyCode->KeyModifier->Void>();
public var onKeyDown(default, null) = new Event<KeyCode->KeyModifier->Int->Void>();
public var onKeyUp(default, null) = new Event<KeyCode->KeyModifier->Int->Void>();
public var onLeave(default, null) = new Event<Void->Void>();
public var onMaximize(default, null) = new Event<Void->Void>();
public var onMinimize(default, null) = new Event<Void->Void>();
Expand Down