@@ -325,6 +325,27 @@ public NativeHookException getException() {
325325 * Native implementation to stop the input hook. There is no other way to stop the hook.
326326 */
327327 public native void disable () throws NativeHookException ;
328+
329+ /**
330+ * Dispatches an event to the appropriate processor. This method is
331+ * generally called by the native library but may be used to synthesize
332+ * native events from Java without replaying them on the native system. If
333+ * you would like to send events to other applications, please use
334+ * {@link #postNativeEvent},
335+ * <p>
336+ *
337+ * <b>Note:</b> This method executes on the native system's event queue.
338+ * It is imperative that all processing be off-loaded to other threads.
339+ * Failure to do so might result in the delay of user input and the automatic
340+ * removal of the native hook.
341+ *
342+ * @param event the <code>NativeInputEvent</code> sent to the registered event listeners.
343+ */
344+ protected static void dispatchEvent (NativeInputEvent event ) {
345+ if (eventExecutor != null ) {
346+ eventExecutor .execute (new EventDispatchTask (event ));
347+ }
348+ }
328349 }
329350
330351
@@ -500,24 +521,20 @@ else if (event instanceof NativeMouseWheelEvent) {
500521 private void processKeyEvent (NativeKeyEvent e ) {
501522 NativeKeyListener [] listeners = eventListeners .getListeners (NativeKeyListener .class );
502523
503- switch ( e . getID () ) {
504- case NativeKeyEvent . NATIVE_KEY_PRESSED :
505- for ( int i = 0 ; i < listeners . length ; i ++) {
524+ for ( int i = 0 ; i < listeners . length ; i ++ ) {
525+ switch ( e . getID ()) {
526+ case NativeKeyEvent . NATIVE_KEY_PRESSED :
506527 listeners [i ].nativeKeyPressed (e );
507- }
508- break ;
528+ break ;
509529
510- case NativeKeyEvent .NATIVE_KEY_TYPED :
511- for (int i = 0 ; i < listeners .length ; i ++) {
530+ case NativeKeyEvent .NATIVE_KEY_TYPED :
512531 listeners [i ].nativeKeyTyped (e );
513- }
514- break ;
532+ break ;
515533
516- case NativeKeyEvent .NATIVE_KEY_RELEASED :
517- for (int i = 0 ; i < listeners .length ; i ++) {
534+ case NativeKeyEvent .NATIVE_KEY_RELEASED :
518535 listeners [i ].nativeKeyReleased (e );
519- }
520- break ;
536+ break ;
537+ }
521538 }
522539 }
523540
@@ -533,24 +550,20 @@ private void processKeyEvent(NativeKeyEvent e) {
533550 private void processButtonEvent (NativeMouseEvent e ) {
534551 NativeMouseListener [] listeners = eventListeners .getListeners (NativeMouseListener .class );
535552
536- switch ( e . getID () ) {
537- case NativeMouseEvent . NATIVE_MOUSE_CLICKED :
538- for ( int i = 0 ; i < listeners . length ; i ++) {
553+ for ( int i = 0 ; i < listeners . length ; i ++ ) {
554+ switch ( e . getID ()) {
555+ case NativeMouseEvent . NATIVE_MOUSE_CLICKED :
539556 listeners [i ].nativeMouseClicked (e );
540- }
541- break ;
557+ break ;
542558
543- case NativeMouseEvent .NATIVE_MOUSE_PRESSED :
544- for (int i = 0 ; i < listeners .length ; i ++) {
559+ case NativeMouseEvent .NATIVE_MOUSE_PRESSED :
545560 listeners [i ].nativeMousePressed (e );
546- }
547- break ;
561+ break ;
548562
549- case NativeMouseEvent .NATIVE_MOUSE_RELEASED :
550- for (int i = 0 ; i < listeners .length ; i ++) {
563+ case NativeMouseEvent .NATIVE_MOUSE_RELEASED :
551564 listeners [i ].nativeMouseReleased (e );
552- }
553- break ;
565+ break ;
566+ }
554567 }
555568 }
556569
@@ -566,18 +579,16 @@ private void processButtonEvent(NativeMouseEvent e) {
566579 private void processMouseEvent (NativeMouseEvent e ) {
567580 NativeMouseMotionListener [] listeners = eventListeners .getListeners (NativeMouseMotionListener .class );
568581
569- switch ( e . getID () ) {
570- case NativeMouseEvent . NATIVE_MOUSE_MOVED :
571- for ( int i = 0 ; i < listeners . length ; i ++) {
582+ for ( int i = 0 ; i < listeners . length ; i ++ ) {
583+ switch ( e . getID ()) {
584+ case NativeMouseEvent . NATIVE_MOUSE_MOVED :
572585 listeners [i ].nativeMouseMoved (e );
573- }
574- break ;
586+ break ;
575587
576- case NativeMouseEvent .NATIVE_MOUSE_DRAGGED :
577- for (int i = 0 ; i < listeners .length ; i ++) {
588+ case NativeMouseEvent .NATIVE_MOUSE_DRAGGED :
578589 listeners [i ].nativeMouseDragged (e );
579- }
580- break ;
590+ break ;
591+ }
581592 }
582593 }
583594
@@ -600,27 +611,6 @@ private void processMouseWheelEvent(NativeMouseWheelEvent e) {
600611 }
601612 }
602613
603- /**
604- * Dispatches an event to the appropriate processor. This method is
605- * generally called by the native library but may be used to synthesize
606- * native events from Java without replaying them on the native system. If
607- * you would like to send events to other applications, please use
608- * {@link #postNativeEvent},
609- * <p>
610- *
611- * <b>Note:</b> This method executes on the native system's event queue.
612- * It is imperative that all processing be off-loaded to other threads.
613- * Failure to do so might result in the delay of user input and the automatic
614- * removal of the native hook.
615- *
616- * @param event the <code>NativeInputEvent</code> sent to the registered event listeners.
617- */
618- protected static void dispatchEvent (NativeInputEvent event ) {
619- if (eventExecutor != null ) {
620- eventExecutor .execute (new EventDispatchTask (event ));
621- }
622- }
623-
624614 /**
625615 * Set a different executor service for native event delivery. By default,
626616 * JNativeHook utilizes a single thread executor to dispatch events from
0 commit comments