Skip to content

Commit

Permalink
expose event time, #20
Browse files Browse the repository at this point in the history
  • Loading branch information
SnosMe committed Sep 14, 2022
1 parent a1b3ff6 commit 63745a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uiohook-napi",
"version": "1.4.0",
"version": "1.5.0",
"author": {
"name": "Alexander Drozdov"
},
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export enum EventType {

export interface UiohookKeyboardEvent {
type: EventType.EVENT_KEY_PRESSED | EventType.EVENT_KEY_RELEASED
time: number
altKey: boolean
ctrlKey: boolean
metaKey: boolean
Expand All @@ -38,6 +39,7 @@ export interface UiohookMouseEvent {
EventType.EVENT_MOUSE_MOVED |
EventType.EVENT_MOUSE_PRESSED |
EventType.EVENT_MOUSE_RELEASED
time: number
altKey: boolean
ctrlKey: boolean
metaKey: boolean
Expand All @@ -50,6 +52,7 @@ export interface UiohookMouseEvent {

export interface UiohookWheelEvent {
type: EventType.EVENT_MOUSE_WHEEL
time: number
altKey: boolean
ctrlKey: boolean
metaKey: boolean
Expand Down
7 changes: 7 additions & 0 deletions src/lib/addon.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@ napi_value uiohook_to_js_event(napi_env env, uiohook_event* event) {
status = napi_get_boolean(env, (event->mask & (MASK_SHIFT)), &e_shiftKey);
NAPI_FATAL_IF_FAILED(status, "uiohook_to_js_event", "napi_get_boolean");

napi_value e_time;
status = napi_create_double(env, (double)event->time, &e_time);
NAPI_FATAL_IF_FAILED(status, "uiohook_to_js_event", "napi_create_double");

if (event->type == EVENT_KEY_PRESSED || event->type == EVENT_KEY_RELEASED) {
napi_value e_keycode;
status = napi_create_uint32(env, event->data.keyboard.keycode, &e_keycode);
NAPI_FATAL_IF_FAILED(status, "uiohook_to_js_event", "napi_create_uint32");

napi_property_descriptor descriptors[] = {
{ "type", NULL, NULL, NULL, NULL, e_type, napi_enumerable, NULL },
{ "time", NULL, NULL, NULL, NULL, e_time, napi_enumerable, NULL },
{ "altKey", NULL, NULL, NULL, NULL, e_altKey, napi_enumerable, NULL },
{ "ctrlKey", NULL, NULL, NULL, NULL, e_ctrlKey, napi_enumerable, NULL },
{ "metaKey", NULL, NULL, NULL, NULL, e_metaKey, napi_enumerable, NULL },
Expand Down Expand Up @@ -89,6 +94,7 @@ napi_value uiohook_to_js_event(napi_env env, uiohook_event* event) {

napi_property_descriptor descriptors[] = {
{ "type", NULL, NULL, NULL, NULL, e_type, napi_enumerable, NULL },
{ "time", NULL, NULL, NULL, NULL, e_time, napi_enumerable, NULL },
{ "altKey", NULL, NULL, NULL, NULL, e_altKey, napi_enumerable, NULL },
{ "ctrlKey", NULL, NULL, NULL, NULL, e_ctrlKey, napi_enumerable, NULL },
{ "metaKey", NULL, NULL, NULL, NULL, e_metaKey, napi_enumerable, NULL },
Expand Down Expand Up @@ -129,6 +135,7 @@ napi_value uiohook_to_js_event(napi_env env, uiohook_event* event) {

napi_property_descriptor descriptors[] = {
{ "type", NULL, NULL, NULL, NULL, e_type, napi_enumerable, NULL },
{ "time", NULL, NULL, NULL, NULL, e_time, napi_enumerable, NULL },
{ "altKey", NULL, NULL, NULL, NULL, e_altKey, napi_enumerable, NULL },
{ "ctrlKey", NULL, NULL, NULL, NULL, e_ctrlKey, napi_enumerable, NULL },
{ "metaKey", NULL, NULL, NULL, NULL, e_metaKey, napi_enumerable, NULL },
Expand Down

0 comments on commit 63745a5

Please sign in to comment.