Skip to content

feat: added keyboard and mouse listener #8909

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

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
7 changes: 5 additions & 2 deletions apps/agent/src/main/workers/pull-activities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { KeyboardMouseCounter } from '@gauzy/desktop-lib';
class PullActivities {
static instance: PullActivities;
private listenerModule: any;
private listenerModule: KeyboardMouseCounter;
private isStarted: boolean;
constructor() {
if (!PullActivities.instance) {
Expand All @@ -20,7 +21,7 @@ class PullActivities {
getListenerModule() {
try {
// this is not implemented yet
this.listenerModule = null;
this.listenerModule = KeyboardMouseCounter.getInstance();
} catch (error) {
console.error('error on get listener module', error);
}
Expand All @@ -32,6 +33,7 @@ class PullActivities {
}
try {
if (!this.isStarted) {
this.listenerModule.startListener();
this.isStarted = true;
}
} catch (error) {
Expand All @@ -44,6 +46,7 @@ class PullActivities {
this.getListenerModule();
}
try {
this.listenerModule.stopListener();
this.isStarted = false;
} catch (error) {
console.error('error to stop tracking', error);
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"tslib": "^2.6.2",
"underscore": "^1.13.3",
"undici": "^6.10.2",
"unzipper": "^0.12.1"
"unzipper": "^0.12.1",
"uiohook-napi": "^1.5.4"

Check warning on line 60 in packages/desktop-lib/package.json

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (uiohook)
},
"devDependencies": {
"@types/node": "^20.14.9",
Expand Down
1 change: 1 addition & 0 deletions packages/desktop-lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ export * from './lib/strategies';
export * from './lib/translation';
export * from './lib/update-server/desktop-local-update-server';
export * from './lib/desktop-theme-listener';
export * from './lib/keyboard-mouse-counter';
52 changes: 52 additions & 0 deletions packages/desktop-lib/src/lib/keyboard-mouse-counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { uIOhook, UiohookKey, UiohookKeyboardEvent, UiohookMouseEvent, UiohookWheelEvent } from 'uiohook-napi'

Check warning on line 1 in packages/desktop-lib/src/lib/keyboard-mouse-counter.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Uiohook)

Check warning on line 1 in packages/desktop-lib/src/lib/keyboard-mouse-counter.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Uiohook)

Check warning on line 1 in packages/desktop-lib/src/lib/keyboard-mouse-counter.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Uiohook)

Check warning on line 1 in packages/desktop-lib/src/lib/keyboard-mouse-counter.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Uiohook)

Check warning on line 1 in packages/desktop-lib/src/lib/keyboard-mouse-counter.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (uiohook)

export class KeyboardMouseCounter {
static instance: KeyboardMouseCounter;
private isStarted: boolean;
constructor() {
if (!KeyboardMouseCounter.instance) {
KeyboardMouseCounter.instance = this;
}
}

static getInstance(): KeyboardMouseCounter {
if (!KeyboardMouseCounter.instance) {
KeyboardMouseCounter.instance = new KeyboardMouseCounter();
return KeyboardMouseCounter.instance;
}
return KeyboardMouseCounter.instance;
}

registerEvent() {
uIOhook.on('keydown', (e: UiohookKeyboardEvent) => {

Check warning on line 21 in packages/desktop-lib/src/lib/keyboard-mouse-counter.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Uiohook)
console.log('keyboard pressed at key', e.keycode);
});

uIOhook.on('click', (e: UiohookMouseEvent) => {
console.log('mouse click at position', `${e.x}, ${e.y}`);
});

uIOhook.on('mousemove', (e: UiohookMouseEvent) => {
console.log('mouse moved at position', `${e.x}. ${e.y}`)
});

uIOhook.on('wheel', (e: UiohookWheelEvent) => {
console.log('mouse wheeled at position', `${e.direction} to ${e.x}, ${e.y}`);
});
}

startListener() {
if (!this.isStarted) {
this.registerEvent();
uIOhook.start();
this.isStarted = true;
}
}

stopListener() {
if (this.isStarted) {
uIOhook.stop();
this.isStarted = false;
}
}
}
Loading