@Override public void whetherMenusAreAccessible() throws Throwable { Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { @Override public void eventDispatched(AWTEvent event) { System.err.println(event); } }, AWTEvent.KEY_EVENT_MASK); if (Platform.getCurrent() == Platform.MAC && System.getProperty("java.version", "").matches("1.[78].*")) { throw new SkipException("Menu mneomonics are not handled on Mac under Java 1.7+"); } exitItemCalled = false; driver.sendKeys(textField, JavaAgentKeys.chord(JavaAgentKeys.ALT, "f")); new WaitWithoutException("Waiting for exit item to be shown") { @Override public boolean until() { return exitItem.isShowing(); } }; driver.click(exitItem, Buttons.LEFT, 1, 0, 0); new WaitWithoutException("Waiting for exit item to be called") { @Override public boolean until() { return exitItemCalled; } }; AssertJUnit.assertEquals(true, exitItemCalled); }
static boolean isLayerEventControllerAdded() { Toolkit toolkit = Toolkit.getDefaultToolkit(); AWTEventListener layerEventController = null; for (AWTEventListener listener : toolkit.getAWTEventListeners()) { if (listener instanceof AWTEventListenerProxy) { listener = ((AWTEventListenerProxy)listener).getListener(); } if ("LayerEventController".equals(listener.getClass().getSimpleName())) { if (layerEventController != null) { throw new RuntimeException("Duplicated LayerEventController"); } layerEventController = listener; } } boolean ret = layerEventController != null; if (ret) { System.out.println("LayerEventController found"); } else { System.out.println("No LayerEventController"); } return ret; }
static boolean layerEventControllerMaskEquals(long mask) { Toolkit toolkit = Toolkit.getDefaultToolkit(); AWTEventListener layerEventController = null; for (AWTEventListener listener : toolkit.getAWTEventListeners(mask)) { if (listener instanceof AWTEventListenerProxy) { listener = ((AWTEventListenerProxy)listener).getListener(); } if ("LayerEventController".equals(listener.getClass().getSimpleName())) { if (layerEventController != null) { throw new RuntimeException("Duplicated LayerEventController"); } layerEventController = listener; } } boolean ret = layerEventController != null; if (ret) { System.out.println("LayerEventController with the correct mask found"); } else { System.out.println("No LayerEventController with the correct mask"); } return ret; }
/** Install a debugging hotkey. When that key is pressed: a new * <code>GraphicsWriterDebugger</code> frame will appear that paints * the argument. * * @param component a component to debug. The <code>paint()</code> method * of this argument will be used. * @param keyCode a <code>KeyEven.VK_X</code> key code. When this key is * pressed, the <code>GraphicsWriterDebugger</code> frame will be created. */ public static void installDebugHotkey(final Component component,final int keyCode) { Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { public void eventDispatched(AWTEvent event) { KeyEvent e = (KeyEvent)event; if(e.getKeyCode()==keyCode && e.getID()==KeyEvent.KEY_PRESSED) { GraphicsWriter writer = new GraphicsWriter(true); component.paint(writer); GraphicsWriterDebugger d = new GraphicsWriterDebugger(writer); d.pack(); d.setVisible(true); } } }, AWTEvent.KEY_EVENT_MASK); }
public static void adjustFocusTraversal(@NotNull Disposable disposable) { if (!SystemInfo.isMacOSSnowLeopard) return; final AWTEventListener listener = new AWTEventListener() { @Override public void eventDispatched(AWTEvent event) { if (event instanceof KeyEvent && ((KeyEvent)event).getKeyCode() == KeyEvent.VK_TAB && (!(event.getSource() instanceof JTextComponent)) && (!(event.getSource() instanceof JList)) && !isFullKeyboardAccessEnabled()) ((KeyEvent)event).consume(); } }; Disposer.register(disposable, new Disposable() { @Override public void dispose() { Toolkit.getDefaultToolkit().removeAWTEventListener(listener); } }); Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.KEY_EVENT_MASK); }
/** * Creates a new help manager object. */ private CHelpManager() { final Image cursorImage = Toolkit.getDefaultToolkit().getImage(CMain.class.getResource("data/help.png")); final java.awt.Point cursorHotSpot = new java.awt.Point(0,0); m_helpCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, cursorHotSpot, "helpCursor"); Toolkit.getDefaultToolkit().addAWTEventListener( new AWTEventListener() { @Override public void eventDispatched(final AWTEvent event) { handleEvent(event); } }, AWTEvent.MOUSE_EVENT_MASK); }
/** * Start tracking activity (globally currently only mouse activity, inside * of the program keypresses and mouse actions). */ public static void startTracking() { if (timer == null) { checkMouseLocation(); timer = new Timer(DELAY, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { checkMouseLocation(); } }); timer.start(); Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { @Override public void eventDispatched(AWTEvent event) { triggerActivity(); } }, AWTEvent.KEY_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK); LOGGER.info("Started tracking user activity.."); } }
public static void start() { if (properties == null) properties = new ScreenShotProperties(); listener = new AWTEventListener() { @Override public void eventDispatched(AWTEvent event) { if (active && properties.useHotkey && ((KeyEvent)event).getKeyCode() == KeyEvent.VK_PRINTSCREEN && event.getID() == KeyEvent.KEY_RELEASED ) { takeScreenshot(ScreenshotType.GAME); ((KeyEvent)event).consume(); } } }; Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.KEY_EVENT_MASK); active = true; }
public static void activateKeyStates() { if (keyStates == null) keyStates = new AdvancedKeyListenerFilter(null, false); // add a global listener Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { public void eventDispatched(AWTEvent e) { if (e instanceof KeyEvent) { switch (e.getID()) { case KeyEvent.KEY_PRESSED: keyStates.keyPressed((KeyEvent)e); break; case KeyEvent.KEY_RELEASED: keyStates.keyReleased((KeyEvent)e); break; case KeyEvent.KEY_TYPED: keyStates.keyTyped((KeyEvent)e); break; } } } }, AWTEvent.KEY_EVENT_MASK); }
private void initActivityMonitor() { lastActivity = System.currentTimeMillis(); final AWTEventListener awtEventListener = new AWTEventListener() { /** {@inheritDoc} */ @Override public void eventDispatched(AWTEvent event) { lastActivity = System.currentTimeMillis(); } }; Toolkit.getDefaultToolkit().addAWTEventListener(awtEventListener, AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK); final Timer activityMonitorTimer = new Timer("ActivityMonitorTimer", true); final TimerTask timerTask = new TimerTask() { /** {@inheritDoc} */ @Override public void run() { if (System.currentTimeMillis() - lastActivity > INACTIVITY_DELAY * 60L * 1000) { exit(1); } } }; // on vérifie l'activité utilisateur toutes les 60 secondes par rapport au délai maximum d'inactivité activityMonitorTimer.schedule(timerTask, 60L * 1000, 60L * 1000); }
private void addVideoFileListeners() { final long eventMask = AWTEvent.KEY_EVENT_MASK; final NumberKeySeekListener keyEventListener = new NumberKeySeekListener(this.videoDisplay); Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { @Override public void eventDispatched(final AWTEvent event) { switch (event.getID()) { case KeyEvent.KEY_PRESSED: final KeyEvent kevent = (KeyEvent) event; keyEventListener.keyPressed(kevent); break; }; } }, eventMask); // rp.addKeyListener(new NumberKeySeekListener(videoDisplay)); }
/** * Starts mouse capture. */ protected void startMouseCapture() throws IOException { mouseCaptureTimer = new ScheduledThreadPoolExecutor(1); int delay = max(1, (int) (1000 / mouseFormat.get(FrameRateKey).doubleValue())); mouseGrabber = new MouseGrabber(this, recordingStartTime, mouseCaptureTimer); mouseFuture = mouseCaptureTimer.scheduleAtFixedRate(mouseGrabber, delay, delay, TimeUnit.MILLISECONDS); final MouseGrabber mouseGrabberF = mouseGrabber; awtEventListener = new AWTEventListener() { @Override public void eventDispatched(AWTEvent event) { if (event.getID() == MouseEvent.MOUSE_PRESSED) { mouseGrabberF.setMousePressed(true); } else if (event.getID() == MouseEvent.MOUSE_RELEASED) { mouseGrabberF.setMousePressed(false); } } }; Toolkit.getDefaultToolkit().addAWTEventListener(awtEventListener, AWTEvent.MOUSE_EVENT_MASK); mouseGrabber.setFuture(mouseFuture); }