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


Java NativeKeyEvent.NATIVE_KEY_PRESSED屬性代碼示例

本文整理匯總了Java中org.jnativehook.keyboard.NativeKeyEvent.NATIVE_KEY_PRESSED屬性的典型用法代碼示例。如果您正苦於以下問題:Java NativeKeyEvent.NATIVE_KEY_PRESSED屬性的具體用法?Java NativeKeyEvent.NATIVE_KEY_PRESSED怎麽用?Java NativeKeyEvent.NATIVE_KEY_PRESSED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.jnativehook.keyboard.NativeKeyEvent的用法示例。


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

示例1: testGetModifiers

/**
 * Test of getModifiers method, of class NativeInputEvent.
 */
@Test
public void testGetModifiers() {
	System.out.println("getModifiers");

	int mask =	NativeInputEvent.ALT_MASK |
				NativeInputEvent.CTRL_MASK |
				NativeInputEvent.META_MASK |
				NativeInputEvent.SHIFT_MASK;

	NativeInputEvent event = new NativeInputEvent(
			GlobalScreen.class,
			NativeKeyEvent.NATIVE_KEY_PRESSED,
			mask);

	assertEquals(event.getModifiers(), mask);
}
 
開發者ID:kwhat,項目名稱:jnativehook,代碼行數:19,代碼來源:NativeInputEventTest.java

示例2: testSetModifiers

/**
 * Test of setModifiers method, of class NativeInputEvent.
 */
@Test
public void testSetModifiers() {
	System.out.println("setModifiers");

	int mask =	NativeInputEvent.BUTTON1_MASK |
				NativeInputEvent.BUTTON2_MASK |
				NativeInputEvent.BUTTON3_MASK |
				NativeInputEvent.BUTTON4_MASK |
				NativeInputEvent.BUTTON5_MASK;

	NativeInputEvent event = new NativeInputEvent(
			GlobalScreen.class,
			NativeKeyEvent.NATIVE_KEY_PRESSED,
			0x00);

	event.setModifiers(mask);
	assertEquals(event.getModifiers(), mask);
}
 
開發者ID:kwhat,項目名稱:jnativehook,代碼行數:21,代碼來源:NativeInputEventTest.java

示例3: testProcessKeyEvent

/**
 * Test of processKeyEvent method, of class GlobalScreen.
 */
@Test
public void testProcessKeyEvent() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InterruptedException {
	System.out.println("processKeyEvent");

	// Setup and event listener.
	NativeKeyListenerImpl listener = new NativeKeyListenerImpl();
	GlobalScreen.addNativeKeyListener(listener);

	// Dispatch a key event and check to see if it was sent.
	NativeKeyEvent event = new NativeKeyEvent(
			NativeKeyEvent.NATIVE_KEY_PRESSED,
			0x00,		// Modifiers
			0x41,		// Raw Code
			NativeKeyEvent.VC_UNDEFINED,
			NativeKeyEvent.CHAR_UNDEFINED,
			NativeKeyEvent.KEY_LOCATION_UNKNOWN);

	synchronized (listener) {
		GlobalScreen.dispatchEvent(event);
		listener.wait(3000);
		assertEquals(event, listener.getLastEvent());
	}

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

示例4: nativeKeyPressed

public void nativeKeyPressed(NativeKeyEvent e) {
	System.out.println("Received " + e.paramString());

	if (e.getID() != NativeKeyEvent.NATIVE_KEY_PRESSED) {
		fail("Invalid event type received for nativeKeyPressed!");
	}

	lastEvent = e;

	synchronized(this) {
		this.notifyAll();
	}

	try {
		Field f = NativeInputEvent.class.getDeclaredField("reserved");
		f.setAccessible(true);
		f.setShort(e, (short) 0x01);
	}
	catch (Exception e1) {
		e1.printStackTrace();
	}
}
 
開發者ID:kwhat,項目名稱:jnativehook,代碼行數:22,代碼來源:NativeKeyListenerImpl.java

示例5: processKeyEvent

/**
 * 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,代碼行數:29,代碼來源:GlobalScreen.java

示例6: testDispatchEvent

/**
 * Test of dispatchEvent method, of class GlobalScreen.
 */
@Test
public void testDispatchEvent() throws InterruptedException, NativeHookException {
	System.out.println("dispatchEvent");

	// Setup and event listener.
	NativeKeyListenerImpl keyListener = new NativeKeyListenerImpl();
	GlobalScreen.addNativeKeyListener(keyListener);

	NativeMouseInputListenerImpl mouseListener = new NativeMouseInputListenerImpl();
	GlobalScreen.addNativeMouseListener(mouseListener);

	NativeMouseWheelListenerImpl wheelListener = new NativeMouseWheelListenerImpl();
	GlobalScreen.addNativeMouseWheelListener(wheelListener);

	// Make sure the native thread is running!
	GlobalScreen.registerNativeHook();

	// Dispatch a key event and check to see if it was sent.
	NativeKeyEvent keyEvent = new NativeKeyEvent(
			NativeKeyEvent.NATIVE_KEY_PRESSED,
			0x00,		// Modifiers
			0x41,		// Raw Code
			NativeKeyEvent.VC_A,
			NativeKeyEvent.CHAR_UNDEFINED,
			NativeKeyEvent.KEY_LOCATION_STANDARD);

	synchronized (keyListener) {
		GlobalScreen.dispatchEvent(keyEvent);
		keyListener.wait(3000);
		assertEquals(keyEvent, keyListener.getLastEvent());
	}


	// Dispatch a mouse event and check to see if it was sent.
	NativeMouseEvent mouseEvent = new NativeMouseEvent(
			NativeMouseEvent.NATIVE_MOUSE_CLICKED,
			0x00,	// Modifiers
			50,		// X
			75,		// Y
			1,		// Click Count
			NativeMouseEvent.BUTTON1);

	synchronized (mouseListener) {
		GlobalScreen.dispatchEvent(mouseEvent);
		mouseListener.wait(3000);
		assertEquals(mouseEvent, mouseListener.getLastEvent());
	}

	// Dispatch a mouse event and check to see if it was sent.
	NativeMouseWheelEvent wheelEvent = new NativeMouseWheelEvent(
			NativeMouseEvent.NATIVE_MOUSE_WHEEL,
			0x00,	// Modifiers
			50,		// X
			75,		// Y
			1,		// Click Count
			NativeMouseWheelEvent.WHEEL_UNIT_SCROLL,
			3,		// Scroll Amount
			-1);	// Wheel Rotation

	synchronized (wheelListener) {
		GlobalScreen.dispatchEvent(wheelEvent);
		wheelListener.wait(3000);
		assertEquals(wheelEvent, wheelListener.getLastEvent());
	}

	// Stop the native thread.
	GlobalScreen.unregisterNativeHook();

	// Remove all added listeners.
	GlobalScreen.removeNativeKeyListener(keyListener);
	GlobalScreen.removeNativeMouseListener(mouseListener);
	GlobalScreen.removeNativeMouseWheelListener(wheelListener);
}
 
開發者ID:kwhat,項目名稱:jnativehook,代碼行數:76,代碼來源:GlobalScreenTest.java

示例7: processKeyEvent

/**
 * 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,代碼行數:28,代碼來源:GlobalScreen.java

示例8: testGetID

/**
 * Test of getID method, of class NativeInputEvent.
 */
@Test
public void testGetID() {
	System.out.println("getID");

	NativeInputEvent event = new NativeInputEvent(
			GlobalScreen.class,
			NativeKeyEvent.NATIVE_KEY_PRESSED,
			0x00);

	assertEquals(event.getID(), NativeKeyEvent.NATIVE_KEY_PRESSED);
}
 
開發者ID:kwhat,項目名稱:jnativehook,代碼行數:14,代碼來源:NativeInputEventTest.java

示例9: testGetWhen

/**
 * Test of getWhen method, of class NativeInputEvent.
 */
@Test
public void testGetWhen() {
	System.out.println("getWhen");

	long when = 0;

	NativeInputEvent event = new NativeInputEvent(
			GlobalScreen.class,
			NativeKeyEvent.NATIVE_KEY_PRESSED,
			0x00);

	assertEquals(event.getWhen(), when);
}
 
開發者ID:kwhat,項目名稱:jnativehook,代碼行數:16,代碼來源:NativeInputEventTest.java

示例10: testParamString

/**
 * Test of paramString method, of class NativeInputEvent.
 */
@Test
public void testParamString() {
	System.out.println("paramString");

	NativeInputEvent event = new NativeInputEvent(
			GlobalScreen.class,
			NativeKeyEvent.NATIVE_KEY_PRESSED,
			NativeInputEvent.SHIFT_MASK |
			NativeInputEvent.BUTTON5_MASK);

	assertFalse(event.paramString().equals(""));
}
 
開發者ID:kwhat,項目名稱:jnativehook,代碼行數:15,代碼來源:NativeInputEventTest.java

示例11: testPostNativeEvent

/**
	 * Test of dispatchEvent method, of class GlobalScreen.
	 */
	@Test
	public void testPostNativeEvent() throws InterruptedException, NativeHookException {
		System.out.println("dispatchEvent");

		// Setup and event listener.
		NativeKeyListenerImpl keyListener = new NativeKeyListenerImpl();
		GlobalScreen.addNativeKeyListener(keyListener);

		NativeMouseInputListenerImpl mouseListener = new NativeMouseInputListenerImpl();
		GlobalScreen.addNativeMouseListener(mouseListener);

		NativeMouseWheelListenerImpl wheelListener = new NativeMouseWheelListenerImpl();
		GlobalScreen.addNativeMouseWheelListener(wheelListener);

		// Make sure the native thread is running!
		GlobalScreen.registerNativeHook();

		// Dispatch a key event and check to see if it was sent.
		NativeKeyEvent keyEvent = new NativeKeyEvent(
				NativeKeyEvent.NATIVE_KEY_PRESSED,
				0x00,		// Modifiers
				0x00,		// Raw Code
				NativeKeyEvent.VC_A,
				NativeKeyEvent.CHAR_UNDEFINED,
				NativeKeyEvent.KEY_LOCATION_STANDARD);

		synchronized (keyListener) {
			GlobalScreen.postNativeEvent(keyEvent);
			keyListener.wait(3000);
			NativeKeyEvent lastEvent = keyListener.getLastEvent();
			assertEquals(keyEvent.getKeyCode(), lastEvent.getKeyCode());
			assertEquals(keyEvent.getRawCode(), lastEvent.getRawCode());
		}

/*
		// Dispatch a mouse event and check to see if it was sent.
		NativeMouseEvent mouseEvent = new NativeMouseEvent(
				NativeMouseEvent.NATIVE_MOUSE_CLICKED,
				System.currentTimeMillis(),
				0x00,	// Modifiers
				50,		// X
				75,		// Y
				1,		// Click Count
				NativeMouseEvent.BUTTON1);

		synchronized (mouseListener) {
			GlobalScreen.postNativeEvent(mouseEvent);
			mouseListener.wait(3000);
			assertEquals(mouseEvent, mouseListener.getLastEvent());
		}

		// Dispatch a mouse event and check to see if it was sent.
		NativeMouseWheelEvent wheelEvent = new NativeMouseWheelEvent(
				NativeMouseEvent.NATIVE_MOUSE_WHEEL,
				System.currentTimeMillis(),
				0x00,	// Modifiers
				50,		// X
				75,		// Y
				1,		// Click Count
				NativeMouseWheelEvent.WHEEL_UNIT_SCROLL,
				3,		// Scroll Amount
				-1);	// Wheel Rotation

		synchronized (wheelListener) {
			GlobalScreen.postNativeEvent(wheelEvent);
			wheelListener.wait(3000);
			assertEquals(wheelEvent, wheelListener.getLastEvent());
		}
*/
		// Stop the native thread.
		GlobalScreen.unregisterNativeHook();

		// Remove all added listeners.
		GlobalScreen.removeNativeKeyListener(keyListener);
		GlobalScreen.removeNativeMouseListener(mouseListener);
		GlobalScreen.removeNativeMouseWheelListener(wheelListener);
	}
 
開發者ID:kwhat,項目名稱:jnativehook,代碼行數:80,代碼來源:GlobalScreenTest.java


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