本文整理汇总了Java中org.jnativehook.mouse.NativeMouseListener类的典型用法代码示例。如果您正苦于以下问题:Java NativeMouseListener类的具体用法?Java NativeMouseListener怎么用?Java NativeMouseListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NativeMouseListener类属于org.jnativehook.mouse包,在下文中一共展示了NativeMouseListener类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processButtonEvent
import org.jnativehook.mouse.NativeMouseListener; //导入依赖的package包/类
/**
* Processes native mouse button events by dispatching them to all registered
* <code>NativeMouseListener</code> objects.
*
* @param e the <code>NativeMouseEvent</code> to dispatch.
* @see NativeMouseEvent
* @see NativeMouseListener
* @see #addNativeMouseListener(NativeMouseListener)
*/
private void processButtonEvent(NativeMouseEvent e) {
NativeMouseListener[] listeners = eventListeners.getListeners(NativeMouseListener.class);
for (int i = 0; i < listeners.length; i++) {
switch (e.getID()) {
case NativeMouseEvent.NATIVE_MOUSE_CLICKED:
listeners[i].nativeMouseClicked(e);
break;
case NativeMouseEvent.NATIVE_MOUSE_PRESSED:
listeners[i].nativeMousePressed(e);
break;
case NativeMouseEvent.NATIVE_MOUSE_RELEASED:
listeners[i].nativeMouseReleased(e);
break;
}
}
}
示例2: testAddNativeMouseListener
import org.jnativehook.mouse.NativeMouseListener; //导入依赖的package包/类
/**
* Test of addNativeMouseListener method, of class GlobalScreen.
*/
@Test
public void testAddNativeMouseListener() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
System.out.println("addNativeMouseListener");
NativeMouseListener listener = new NativeMouseInputListenerImpl();
GlobalScreen.addNativeMouseListener(listener);
Field eventListeners = GlobalScreen.class.getDeclaredField("eventListeners");
eventListeners.setAccessible(true);
EventListenerList listeners = (EventListenerList) eventListeners.get(GlobalScreen.class);
boolean found = false;
NativeMouseListener[] nativeKeyListeners = listeners.getListeners(NativeMouseListener.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.removeNativeMouseListener(listener);
}
示例3: testRemoveNativeMouseListener
import org.jnativehook.mouse.NativeMouseListener; //导入依赖的package包/类
/**
* Test of removeNativeMouseListener method, of class GlobalScreen.
*/
@Test
public void testRemoveNativeMouseListener() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
System.out.println("removeNativeMouseListener");
NativeMouseListener listener = new NativeMouseInputListenerImpl();
GlobalScreen.addNativeMouseListener(listener);
GlobalScreen.removeNativeMouseListener(listener);
Field eventListeners = GlobalScreen.class.getDeclaredField("eventListeners");
eventListeners.setAccessible(true);
EventListenerList listeners = (EventListenerList) eventListeners.get(GlobalScreen.class);
boolean found = false;
NativeMouseListener[] nativeKeyListeners = listeners.getListeners(NativeMouseListener.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!");
}
}
示例4: processMouseEvent
import org.jnativehook.mouse.NativeMouseListener; //导入依赖的package包/类
/**
* Processes native mouse events by dispatching them to all registered
* <code>NativeMouseListener</code> objects.
*
* @param e the <code>NativeMouseEvent</code> to dispatch.
* @see NativeMouseEvent
* @see NativeMouseListener
* @see #addNativeMouseListener(NativeMouseListener)
*/
protected void processMouseEvent(NativeMouseEvent e) {
int id = e.getID();
EventListener[] listeners;
if (id == NativeMouseEvent.NATIVE_MOUSE_MOVED || id == NativeMouseEvent.NATIVE_MOUSE_DRAGGED) {
listeners = eventListeners.getListeners(NativeMouseMotionListener.class);
}
else {
listeners = eventListeners.getListeners(NativeMouseListener.class);
}
for (int i = 0; i < listeners.length; i++) {
switch (id) {
case NativeMouseEvent.NATIVE_MOUSE_CLICKED:
((NativeMouseListener) listeners[i]).nativeMouseClicked(e);
break;
case NativeMouseEvent.NATIVE_MOUSE_PRESSED:
((NativeMouseListener) listeners[i]).nativeMousePressed(e);
break;
case NativeMouseEvent.NATIVE_MOUSE_RELEASED:
((NativeMouseListener) listeners[i]).nativeMouseReleased(e);
break;
case NativeMouseEvent.NATIVE_MOUSE_MOVED:
((NativeMouseMotionListener) listeners[i]).nativeMouseMoved(e);
break;
case NativeMouseEvent.NATIVE_MOUSE_DRAGGED:
((NativeMouseMotionListener) listeners[i]).nativeMouseDragged(e);
break;
}
}
}
示例5: addNativeMouseListener
import org.jnativehook.mouse.NativeMouseListener; //导入依赖的package包/类
/**
* Adds the specified native mouse listener to receive mouse events from the
* native system. If listener is null, no exception is thrown and no action
* is performed.
*
* @param listener a native mouse listener object
*/
public static void addNativeMouseListener(NativeMouseListener listener) {
if (listener != null) {
eventListeners.add(NativeMouseListener.class, listener);
}
}
示例6: removeNativeMouseListener
import org.jnativehook.mouse.NativeMouseListener; //导入依赖的package包/类
/**
* Removes the specified native mouse listener so that it no longer receives
* mouse 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 mouse listener object
*/
public static void removeNativeMouseListener(NativeMouseListener listener) {
if (listener != null) {
eventListeners.remove(NativeMouseListener.class, listener);
}
}
示例7: addNativeMouseListener
import org.jnativehook.mouse.NativeMouseListener; //导入依赖的package包/类
/**
* Adds the specified native mouse listener to receive mouse events from the
* native system. If listener is null, no exception is thrown and no action
* is performed.
*
* @param listener a native mouse listener object
*/
public void addNativeMouseListener(NativeMouseListener listener) {
if (listener != null) {
eventListeners.add(NativeMouseListener.class, listener);
}
}
示例8: removeNativeMouseListener
import org.jnativehook.mouse.NativeMouseListener; //导入依赖的package包/类
/**
* Removes the specified native mouse listener so that it no longer receives
* mouse 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 mouse listener object
*/
public void removeNativeMouseListener(NativeMouseListener listener) {
if (listener != null) {
eventListeners.remove(NativeMouseListener.class, listener);
}
}