當前位置: 首頁>>代碼示例>>Java>>正文


Java NativeKeyListener類代碼示例

本文整理匯總了Java中org.jnativehook.keyboard.NativeKeyListener的典型用法代碼示例。如果您正苦於以下問題:Java NativeKeyListener類的具體用法?Java NativeKeyListener怎麽用?Java NativeKeyListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NativeKeyListener類屬於org.jnativehook.keyboard包,在下文中一共展示了NativeKeyListener類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testAddNativeKeyListener

import org.jnativehook.keyboard.NativeKeyListener; //導入依賴的package包/類
/**
 * Test of addNativeKeyListener method, of class GlobalScreen.
 */
@Test
public void testAddNativeKeyListener() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
	System.out.println("addNativeKeyListener");

	NativeKeyListener listener = new NativeKeyListenerImpl();
	GlobalScreen.addNativeKeyListener(listener);

	Field eventListeners = GlobalScreen.class.getDeclaredField("eventListeners");
	eventListeners.setAccessible(true);
	EventListenerList listeners = (EventListenerList) eventListeners.get(GlobalScreen.class);

	boolean found = false;
	NativeKeyListener[] nativeKeyListeners = listeners.getListeners(NativeKeyListener.class);
	for (int i = 0; i < nativeKeyListeners.length && !found; i++) {
		if (nativeKeyListeners[i].equals(listener)) {
			found = true;
		}
	}

	if (!found) {
		fail("Could not find the listener after it was added!");
	}

	GlobalScreen.removeNativeKeyListener(listener);
}
 
開發者ID:kwhat,項目名稱:jnativehook,代碼行數:29,代碼來源:GlobalScreenTest.java

示例2: testRemoveNativeKeyListener

import org.jnativehook.keyboard.NativeKeyListener; //導入依賴的package包/類
/**
 * Test of removeNativeKeyListener method, of class GlobalScreen.
 */
@Test
public void testRemoveNativeKeyListener() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
	System.out.println("removeNativeKeyListener");

	NativeKeyListener listener = new NativeKeyListenerImpl();
	GlobalScreen.addNativeKeyListener(listener);
	GlobalScreen.removeNativeKeyListener(listener);

	Field eventListeners = GlobalScreen.class.getDeclaredField("eventListeners");
	eventListeners.setAccessible(true);
	EventListenerList listeners = (EventListenerList) eventListeners.get(GlobalScreen.class);

	boolean found = false;
	NativeKeyListener[] nativeKeyListeners = listeners.getListeners(NativeKeyListener.class);
	for (int i = 0; i < nativeKeyListeners.length && !found; i++) {
		if (nativeKeyListeners[i].equals(listener)) {
			found = true;
		}
	}

	if (found) {
		fail("Found the listener after it was removed!");
	}
}
 
開發者ID:kwhat,項目名稱:jnativehook,代碼行數:28,代碼來源:GlobalScreenTest.java

示例3: processKeyEvent

import org.jnativehook.keyboard.NativeKeyListener; //導入依賴的package包/類
/**
 * Processes native key events by dispatching them to all registered
 * <code>NativeKeyListener</code> objects.
 *
 * @param e the <code>NativeKeyEvent</code> to dispatch.
 * @see NativeKeyEvent
 * @see NativeKeyListener
 * @see #addNativeKeyListener(NativeKeyListener)
 */
protected void processKeyEvent(NativeKeyEvent e) {
	int id = e.getID();
	EventListener[] listeners = eventListeners.getListeners(NativeKeyListener.class);

	for (int i = 0; i < listeners.length; i++) {
		switch (id) {
			case NativeKeyEvent.NATIVE_KEY_PRESSED:
				((NativeKeyListener) listeners[i]).nativeKeyPressed(e);
				break;

			case NativeKeyEvent.NATIVE_KEY_TYPED:
				((NativeKeyListener) listeners[i]).nativeKeyTyped(e);
				break;

			case NativeKeyEvent.NATIVE_KEY_RELEASED:
				((NativeKeyListener) listeners[i]).nativeKeyReleased(e);
				break;
		}
	}
}
 
開發者ID:Hual,項目名稱:UploadR,代碼行數:30,代碼來源:GlobalScreen.java

示例4: processKeyEvent

import org.jnativehook.keyboard.NativeKeyListener; //導入依賴的package包/類
/**
 * Processes native key events by dispatching them to all registered
 * <code>NativeKeyListener</code> objects.
 *
 * @param e the <code>NativeKeyEvent</code> to dispatch.
 * @see NativeKeyEvent
 * @see NativeKeyListener
 * @see #addNativeKeyListener(NativeKeyListener)
 */
private void processKeyEvent(NativeKeyEvent e) {
	NativeKeyListener[] listeners = eventListeners.getListeners(NativeKeyListener.class);

	for (int i = 0; i < listeners.length; i++) {
		switch (e.getID()) {
			case NativeKeyEvent.NATIVE_KEY_PRESSED:
				listeners[i].nativeKeyPressed(e);
				break;

			case NativeKeyEvent.NATIVE_KEY_TYPED:
				listeners[i].nativeKeyTyped(e);
				break;

			case NativeKeyEvent.NATIVE_KEY_RELEASED:
				listeners[i].nativeKeyReleased(e);
				break;
		}
	}
}
 
開發者ID:kwhat,項目名稱:jnativehook,代碼行數:29,代碼來源:GlobalScreen.java

示例5: registerGlobalKeyListener

import org.jnativehook.keyboard.NativeKeyListener; //導入依賴的package包/類
/**
 * Register a NativeKeyListener to receive ALL KeyEvents
 */
public static void registerGlobalKeyListener(NativeKeyListener listener) {
    GlobalScreen.addNativeKeyListener(listener);
}
 
開發者ID:Matt529,項目名稱:CCAutotyper,代碼行數:7,代碼來源:Autotyper.java

示例6: unregisterGlobalKeyListener

import org.jnativehook.keyboard.NativeKeyListener; //導入依賴的package包/類
/**
 * Unregister a NativeKeyListener
 */
public static void unregisterGlobalKeyListener(NativeKeyListener listener) {
    GlobalScreen.removeNativeKeyListener(listener);
}
 
開發者ID:Matt529,項目名稱:CCAutotyper,代碼行數:7,代碼來源:Autotyper.java

示例7: addNativeKeyListener

import org.jnativehook.keyboard.NativeKeyListener; //導入依賴的package包/類
/**
 * Adds the specified native key listener to receive key events from the
 * native system. If listener is null, no exception is thrown and no action
 * is performed.
 *
 * @param listener a native key listener object
 */
public static void addNativeKeyListener(NativeKeyListener listener) {
	if (listener != null) {
		eventListeners.add(NativeKeyListener.class, listener);
	}
}
 
開發者ID:kwhat,項目名稱:jnativehook,代碼行數:13,代碼來源:GlobalScreen.java

示例8: removeNativeKeyListener

import org.jnativehook.keyboard.NativeKeyListener; //導入依賴的package包/類
/**
 * Removes the specified native key listener so that it no longer receives
 * key events from the native system. This method performs no function if
 * the listener specified by the argument was not previously added.  If
 * listener is null, no exception is thrown and no action is performed.
 *
 * @param listener a native key listener object
 */
public static void removeNativeKeyListener(NativeKeyListener listener) {
	if (listener != null) {
		eventListeners.remove(NativeKeyListener.class, listener);
	}
}
 
開發者ID:kwhat,項目名稱:jnativehook,代碼行數:14,代碼來源:GlobalScreen.java

示例9: addNativeKeyListener

import org.jnativehook.keyboard.NativeKeyListener; //導入依賴的package包/類
/**
 * Adds the specified native key listener to receive key events from the
 * native system. If listener is null, no exception is thrown and no action
 * is performed.
 *
 * @param listener a native key listener object
 */
public void addNativeKeyListener(NativeKeyListener listener) {
	if (listener != null) {
		eventListeners.add(NativeKeyListener.class, listener);
	}
}
 
開發者ID:Hual,項目名稱:UploadR,代碼行數:13,代碼來源:GlobalScreen.java

示例10: removeNativeKeyListener

import org.jnativehook.keyboard.NativeKeyListener; //導入依賴的package包/類
/**
 * Removes the specified native key listener so that it no longer receives
 * key events from the native system. This method performs no function if
 * the listener specified by the argument was not previously added.  If
 * listener is null, no exception is thrown and no action is performed.
 *
 * @param listener a native key listener object
 */
public void removeNativeKeyListener(NativeKeyListener listener) {
	if (listener != null) {
		eventListeners.remove(NativeKeyListener.class, listener);
	}
}
 
開發者ID:Hual,項目名稱:UploadR,代碼行數:14,代碼來源:GlobalScreen.java


注:本文中的org.jnativehook.keyboard.NativeKeyListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。