1
1
/* JNativeHook: Global keyboard and mouse hooking for Java.
2
- * Copyright (C) 2006-2018 Alexander Barker. All Rights Received.
2
+ * Copyright (C) 2006-2018 Alexander Barker. All Rights Received.
3
3
* https://github.com/kwhat/jnativehook/
4
4
*
5
5
* JNativeHook is free software: you can redistribute it and/or modify
9
9
*
10
10
* JNativeHook is distributed in the hope that it will be useful,
11
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
13
* GNU General Public License for more details.
14
14
*
15
15
* You should have received a copy of the GNU Lesser General Public License
16
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
*/
18
18
package org .jnativehook ;
19
19
30
30
import java .io .File ;
31
31
import java .util .Iterator ;
32
32
import java .util .concurrent .ExecutorService ;
33
+ import java .util .logging .Level ;
33
34
import java .util .logging .Logger ;
34
35
35
36
/**
@@ -50,7 +51,13 @@ public class GlobalScreen {
50
51
/**
51
52
* Logging service for the native library.
52
53
*/
53
- protected static Logger log = Logger .getLogger (GlobalScreen .class .getPackage ().getName ());
54
+ protected static Logger logger = Logger .getLogger (GlobalScreen .class .getPackage ().getName ());
55
+ static {
56
+ logger .setLevel (Level .WARNING );
57
+ logger .setUseParentHandlers (false );
58
+ }
59
+
60
+ protected GlobalScreen () { }
54
61
55
62
/**
56
63
* The service to control the hook.
@@ -91,7 +98,7 @@ public class GlobalScreen {
91
98
}
92
99
catch (Exception e ) {
93
100
// There was a problem instantiating the library loader.
94
- log .severe (e .getMessage ());
101
+ logger .severe (e .getMessage ());
95
102
96
103
throw new UnsatisfiedLinkError (e .getMessage ());
97
104
}
@@ -130,13 +137,10 @@ public class GlobalScreen {
130
137
}
131
138
}
132
139
133
-
134
- protected GlobalScreen () { }
135
-
136
140
/**
137
141
* Adds the specified native key listener to receive key events from the
138
- * native system. If listener is null, no exception is thrown and no action
139
- * is performed.
142
+ * native system.
143
+ * If listener is null, no exception is thrown and no action is performed.
140
144
*
141
145
* @param listener a native key listener object
142
146
*/
@@ -149,8 +153,8 @@ public static void addNativeKeyListener(NativeKeyListener listener) {
149
153
/**
150
154
* Removes the specified native key listener so that it no longer receives
151
155
* key events from the native system. This method performs no function if
152
- * the listener specified by the argument was not previously added. If
153
- * listener is null, no exception is thrown and no action is performed.
156
+ * the listener specified by the argument was not previously added.I
157
+ * If listener is null, no exception is thrown and no action is performed.
154
158
*
155
159
* @param listener a native key listener object
156
160
*/
@@ -162,8 +166,8 @@ public static void removeNativeKeyListener(NativeKeyListener listener) {
162
166
163
167
/**
164
168
* Adds the specified native mouse listener to receive mouse events from the
165
- * native system. If listener is null, no exception is thrown and no action
166
- * is performed.
169
+ * native system.
170
+ * If listener is null, no exception is thrown and no action is performed.
167
171
*
168
172
* @param listener a native mouse listener object
169
173
*/
@@ -176,8 +180,8 @@ public static void addNativeMouseListener(NativeMouseListener listener) {
176
180
/**
177
181
* Removes the specified native mouse listener so that it no longer receives
178
182
* mouse events from the native system. This method performs no function if
179
- * the listener specified by the argument was not previously added. If
180
- * listener is null, no exception is thrown and no action is performed.
183
+ * the listener specified by the argument was not previously added.
184
+ * If listener is null, no exception is thrown and no action is performed.
181
185
*
182
186
* @param listener a native mouse listener object
183
187
*/
@@ -189,8 +193,8 @@ public static void removeNativeMouseListener(NativeMouseListener listener) {
189
193
190
194
/**
191
195
* Adds the specified native mouse motion listener to receive mouse motion
192
- * events from the native system. If listener is null, no exception is
193
- * thrown and no action is performed.
196
+ * events from the native system.
197
+ * If listener is null, no exception is thrown and no action is performed.
194
198
*
195
199
* @param listener a native mouse motion listener object
196
200
*/
@@ -204,8 +208,8 @@ public static void addNativeMouseMotionListener(NativeMouseMotionListener listen
204
208
* Removes the specified native mouse motion listener so that it no longer
205
209
* receives mouse motion events from the native system. This method performs
206
210
* no function if the listener specified by the argument was not previously
207
- * added. If listener is null, no exception is thrown and no action is
208
- * performed.
211
+ * added.
212
+ * If listener is null, no exception is thrown and no action is performed.
209
213
*
210
214
* @param listener a native mouse motion listener object
211
215
*/
@@ -217,8 +221,8 @@ public static void removeNativeMouseMotionListener(NativeMouseMotionListener lis
217
221
218
222
/**
219
223
* Adds the specified native mouse wheel listener to receive mouse wheel
220
- * events from the native system. If listener is null, no exception is
221
- * thrown and no action is performed.
224
+ * events from the native system.
225
+ * If listener is null, no exception is thrown and no action is performed.
222
226
*
223
227
* @param listener a native mouse wheel listener object
224
228
* @since 1.1
@@ -233,8 +237,8 @@ public static void addNativeMouseWheelListener(NativeMouseWheelListener listener
233
237
* Removes the specified native mouse wheel listener so that it no longer
234
238
* receives mouse wheel events from the native system. This method performs
235
239
* no function if the listener specified by the argument was not previously
236
- * added. If listener is null, no exception is thrown and no action is
237
- * performed.
240
+ * added.
241
+ * If listener is null, no exception is thrown and no action is performed.
238
242
*
239
243
* @param listener a native mouse wheel listener object
240
244
* @since 1.1
@@ -346,25 +350,25 @@ public NativeHookException getException() {
346
350
}
347
351
348
352
/**
349
- * Native implementation to start the input hook. This method blocks and should only be called by this
350
- * specialized thread implementation. This method will notifyAll() after passing any exception exception
353
+ * Native implementation to start the input hook. This method blocks and should only be called by this
354
+ * specialized thread implementation. This method will notifyAll() after passing any exception exception
351
355
* throwing code.
352
356
*
353
357
* @throws NativeHookException problem registering the native hook with the underlying operating system.
354
358
*/
355
359
protected native void enable () throws NativeHookException ;
356
360
357
361
/**
358
- * Native implementation to stop the input hook. There is no other way to stop the hook.
362
+ * Native implementation to stop the input hook. There is no other way to stop the hook.
359
363
*
360
364
* @throws NativeHookException problem un-registering the native hook with the underlying operating system.
361
365
*/
362
366
public native void disable () throws NativeHookException ;
363
367
364
368
/**
365
- * Dispatches an event to the appropriate processor. This method is
369
+ * Dispatches an event to the appropriate processor. This method is
366
370
* generally called by the native library but may be used to synthesize
367
- * native events from Java without replaying them on the native system. If
371
+ * native events from Java without replaying them on the native system. If
368
372
* you would like to send events to other applications, please use
369
373
* {@link #postNativeEvent},
370
374
* <p>
@@ -408,7 +412,7 @@ public static void registerNativeHook() throws NativeHookException {
408
412
Thread .sleep (250 );
409
413
}
410
414
catch (InterruptedException e ) {
411
- log .warning (e .getMessage ());
415
+ logger .warning (e .getMessage ());
412
416
break ;
413
417
}
414
418
}
@@ -480,36 +484,36 @@ public static boolean isNativeHookRegistered() {
480
484
*
481
485
* For both <code>NATIVE_KEY_PRESSED</code> and
482
486
* <code>NATIVE_KEY_RELEASED</code> events, the virtual keycode and modifier
483
- * mask are used in the creation of the native event. Please note that some
487
+ * mask are used in the creation of the native event. Please note that some
484
488
* platforms may generate <code>NATIVE_KEY_PRESSED</code> and
485
489
* <code>NATIVE_KEY_RELEASED</code> events for each required modifier.
486
490
* <code>NATIVE_KEY_TYPED</code> events will first translate the associated
487
491
* keyChar to its respective virtual code and then produce a
488
492
* <code>NATIVE_KEY_PRESSED</code> followed by a <code>NATIVE_KEY_RELEASED</code>
489
- * event using that virtual code. If the JNativeHook is unable to translate
493
+ * event using that virtual code. If the JNativeHook is unable to translate
490
494
* the keyChar to its respective virtual code, the event is ignored.
491
495
* <p>
492
496
*
493
497
* <code>NativeMouseEvents</code> are processed in much the same way as the
494
- * <code>NativeKeyEvents</code>. Both <code>NATIVE_MOUSE_PRESSED</code> and
498
+ * <code>NativeKeyEvents</code>. Both <code>NATIVE_MOUSE_PRESSED</code> and
495
499
* <code>NATIVE_MOUSE_RELEASED</code> produce events corresponding to the
496
- * event's button code. Keyboard modifiers may be used in conjunction with
500
+ * event's button code. Keyboard modifiers may be used in conjunction with
497
501
* button press and release events, however, they might produce events for each
498
- * modifier. <code>NATIVE_MOUSE_CLICKED</code> events produce a
502
+ * modifier. <code>NATIVE_MOUSE_CLICKED</code> events produce a
499
503
* <code>NATIVE_MOUSE_PRESSED</code> event followed by a
500
504
* <code>NATIVE_MOUSE_RELEASED</code> for the assigned event button.
501
505
* <p>
502
506
*
503
507
* <code>NATIVE_MOUSE_DRAGGED</code> and <code>NATIVE_MOUSE_MOVED</code> events
504
- * are handled identically. In order to produce a <code>NATIVE_MOUSE_DRAGGED</code>
508
+ * are handled identically. In order to produce a <code>NATIVE_MOUSE_DRAGGED</code>
505
509
* event, you must specify a button modifier mask that contains at least one
506
- * button modifier and assign it to the event. Failure to do so will produce a
510
+ * button modifier and assign it to the event. Failure to do so will produce a
507
511
* <code>NATIVE_MOUSE_MOVED</code> event even if the event id was set to
508
512
* <code>NATIVE_MOUSE_DRAGGED</code>.
509
513
* <p>
510
514
*
511
515
* <code>NATIVE_MOUSE_WHEEL</code> events are identical to
512
- * <code>NATIVE_MOUSE_PRESSED</code> events. Wheel events will only produce
516
+ * <code>NATIVE_MOUSE_PRESSED</code> events. Wheel events will only produce
513
517
* pressed events and will never produce <code>NATIVE_MOUSE_RELEASED</code>,
514
518
* <code>NATIVE_MOUSE_DRAGGED</code> or <code>NATIVE_MOUSE_MOVED</code>
515
519
*
@@ -666,9 +670,9 @@ private void processMouseWheelEvent(NativeMouseWheelEvent nativeEvent) {
666
670
}
667
671
668
672
/**
669
- * Set a different executor service for native event delivery. By default,
673
+ * Set a different executor service for native event delivery. By default,
670
674
* JNativeHook utilizes a single thread executor to dispatch events from
671
- * the native event queue. You may choose to use an alternative approach
675
+ * the native event queue. You may choose to use an alternative approach
672
676
* for event delivery by implementing an <code>ExecutorService</code>.
673
677
* <p>
674
678
* <b>Note:</b> Using null as an <code>ExecutorService</code> will cause all
0 commit comments