本文整理汇总了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);
}
示例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!");
}
}
示例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;
}
}
}
示例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;
}
}
}
示例5: registerGlobalKeyListener
import org.jnativehook.keyboard.NativeKeyListener; //导入依赖的package包/类
/**
* Register a NativeKeyListener to receive ALL KeyEvents
*/
public static void registerGlobalKeyListener(NativeKeyListener listener) {
GlobalScreen.addNativeKeyListener(listener);
}
示例6: unregisterGlobalKeyListener
import org.jnativehook.keyboard.NativeKeyListener; //导入依赖的package包/类
/**
* Unregister a NativeKeyListener
*/
public static void unregisterGlobalKeyListener(NativeKeyListener listener) {
GlobalScreen.removeNativeKeyListener(listener);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}