File tree 4 files changed +29
-10
lines changed
4 files changed +29
-10
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class IOCallback{
19
19
return function ( msg ) {
20
20
21
21
if ( that . active == false ) return ;
22
-
22
+ if ( msg == undefined ) { console . log ( msg ) ; return ; }
23
23
if ( msg . type == 3 )
24
24
{
25
25
if ( that . _cbObject [ "keypress" ] )
@@ -131,6 +131,10 @@ class IOHook {
131
131
this . callback . active = true ;
132
132
}
133
133
134
+ stop ( ) {
135
+ NodeHookAddon . stop_hook ( ) ;
136
+ }
137
+
134
138
}
135
139
136
140
module . exports = IOHook ;
Original file line number Diff line number Diff line change @@ -29,17 +29,15 @@ function createWindow () {
29
29
mainWindow = new BrowserWindow ( { width : 800 , height : 600 } ) ;
30
30
31
31
// and load the index.html of the app.
32
- mainWindow . loadURL ( 'file://' + __dirname + '/index.html' ) ;
33
-
34
-
32
+ mainWindow . loadURL ( "http://www.google.com" ) ;
35
33
36
34
//install event listener
37
- ioHook . on ( "keypress" , function ( msg ) { console . log ( msg ) } )
35
+ ioHook . on ( "keyup" , function ( msg ) { console . log ( msg ) ; if ( msg . keyboard . keycode == 57 ) {
36
+ ioHook . stop ( )
37
+ }
38
+ } )
38
39
ioHook . on ( "mousemove" , function ( msg ) { console . log ( msg ) } )
39
40
40
-
41
-
42
-
43
41
mainWindow . on ( "focus" , function ( )
44
42
{
45
43
ioHook . resume ( ) ;
Original file line number Diff line number Diff line change @@ -35,10 +35,14 @@ void HookProcessWorker::Execute(const Nan::AsyncProgressWorkerBase<uiohook_event
35
35
hook_set_logger_proc (&logger_proc);
36
36
hook_set_dispatch_proc (&dispatch_proc);
37
37
fHookExecution = &progress;
38
- std::cout << hook_run ();
39
-
38
+ hook_run ();
40
39
}
41
40
41
+ void HookProcessWorker::Stop ()
42
+ {
43
+ hook_stop ();
44
+ sIsRuning = false ;
45
+ }
42
46
void HookProcessWorker::HandleProgressCallback (const uiohook_event *data, size_t size)
43
47
{
44
48
HandleScope scope (Isolate::GetCurrent ());
@@ -106,13 +110,24 @@ NAN_METHOD(StartHook) {
106
110
}
107
111
}
108
112
113
+ NAN_METHOD (StopHook) {
114
+
115
+ // allow one single execution
116
+ if ((sIsRuning == true ) && (sIOHook !=nullptr ))
117
+ {
118
+ sIOHook ->Stop ();
119
+ }
120
+ }
109
121
110
122
NAN_MODULE_INIT (Init) {
111
123
112
124
113
125
114
126
Nan::Set (target, Nan::New<String>(" start_hook" ).ToLocalChecked (),
115
127
Nan::GetFunction (Nan::New<FunctionTemplate>(StartHook)).ToLocalChecked ());
128
+
129
+ Nan::Set (target, Nan::New<String>(" stop_hook" ).ToLocalChecked (),
130
+ Nan::GetFunction (Nan::New<FunctionTemplate>(StopHook)).ToLocalChecked ());
116
131
}
117
132
118
133
NODE_MODULE (nodeHook, Init)
Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ class HookProcessWorker : public Nan::AsyncProgressWorkerBase<uiohook_event>
18
18
19
19
void HandleProgressCallback (const uiohook_event *data, size_t size);
20
20
21
+ void Stop ();
22
+
21
23
const HookExecution* fHookExecution ;
22
24
23
25
};
You can’t perform that action at this time.
0 commit comments