protected boolean isCtrtlDown(final InputState state) { if (System.getProperty("mrj.version") != null) { // mac return state.getKeyboardState().isAtLeastOneDown(Key.LEFT_META, Key.RIGHT_META); } else { // non-mac return state.getKeyboardState().isAtLeastOneDown(Key.LEFT_CONTROL, Key.RIGHT_CONTROL); } }
protected boolean isShiftDown(final InputState state) { return state.getKeyboardState().isAtLeastOneDown(Key.LEFT_SHIFT, Key.RIGHT_SHIFT); }
public boolean apply(final TwoInputStates states) { final InputState currentState = states.getCurrent(); final InputState previousState = states.getPrevious(); return currentState.getKeyboardState().getKeysReleasedSince(previousState.getKeyboardState()).contains(key); } }
public boolean apply(final TwoInputStates states) { final InputState currentState = states.getCurrent(); final InputState previousState = states.getPrevious(); return currentState.getKeyboardState().getKeysPressedSince(previousState.getKeyboardState()).contains(key); } }
public boolean apply(final TwoInputStates states) { final InputState currentState = states.getCurrent(); final InputState previousState = states.getPrevious(); return currentState.getKeyboardState().getKeysPressedSince(previousState.getKeyboardState()).contains(key); } }
public boolean apply(final TwoInputStates twoInputStates) { final InputState currentState = twoInputStates.getCurrent(); final InputState previousState = twoInputStates.getPrevious(); return !currentState.getKeyboardState().getKeysPressedSince(previousState.getKeyboardState()).isEmpty(); } }
public boolean apply(final TwoInputStates twoInputStates) { final InputState currentState = twoInputStates.getCurrent(); final InputState previousState = twoInputStates.getPrevious(); return !currentState.getKeyboardState().getKeysPressedSince(previousState.getKeyboardState()).isEmpty(); } }
public boolean apply(final TwoInputStates states) { final InputState currentState = states.getCurrent(); final InputState previousState = states.getPrevious(); return currentState.getKeyboardState().getKeysReleasedSince(previousState.getKeyboardState()).contains(key); } }
public boolean apply(final TwoInputStates states) { return states.getCurrent().getKeyboardState().isDown(key); } }
public boolean apply(final TwoInputStates states) { return states.getCurrent().getKeyboardState().isDown(key); } }
public boolean apply(final TwoInputStates states) { for (final Key k : keys) { if (states.getCurrent() != null && states.getCurrent().getKeyboardState().isDown(k)) { return true; } } return false; } };
public boolean apply(final TwoInputStates states) { for (final Key k : keys) { if (states.getCurrent() != null && states.getCurrent().getKeyboardState().isDown(k)) { return true; } } return false; } };
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { FirstPersonControl.this.move(source.getCanvasRenderer().getCamera(), inputStates.getCurrent() .getKeyboardState(), tpf); } };
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { FirstPersonControl.this.move(source.getCanvasRenderer().getCamera(), inputStates.getCurrent() .getKeyboardState(), tpf); } };
@Override public boolean mousePressed(final MouseButton button, final InputState state) { if (button != MouseButton.LEFT) { return super.mousePressed(button, state); } final boolean copyToggled = state.getKeyboardState().isAtLeastOneDown(Key.LEFT_SHIFT, Key.RIGHT_SHIFT); updateSelection(state.getMouseState(), copyToggled); return true; }
@Test public void testLostFocus1() throws Exception { keyboardWrapper.init(); mouseWrapper.init(); controllerWrapper.init(); gestureWrapper.init(); focusWrapper.init(); expect(keyboardWrapper.getEvents()).andReturn(Iterators.peekingIterator(Adown.iterator())); expect(keyboardWrapper.getEvents()).andReturn(Iterators.peekingIterator(noKeys.iterator())); expect(mouseWrapper.getEvents()).andReturn(Iterators.peekingIterator(noMice.iterator())).times(2); expect(controllerWrapper.getEvents()).andReturn(Iterators.peekingIterator(nothing.iterator())).times(2); expect(gestureWrapper.getEvents()).andReturn(Iterators.peekingIterator(noGestures.iterator())).times(2); expect(focusWrapper.getAndClearFocusLost()).andReturn(true); replay(mocks); pl.readState(); inputStates = pl.drainAvailableStates(); assertEquals("2 states", 2, inputStates.size()); is = inputStates.get(0); assertTrue("a down", is.getKeyboardState().isDown(Key.A)); assertFalse("b down", is.getKeyboardState().isDown(Key.B)); assertTrue("lost focus", InputState.LOST_FOCUS == inputStates.get(1)); }
@Test public void testKeyboardBasic2() throws Exception { final PeekingIterator<KeyEvent> adau = Iterators.peekingIterator(AdownAup.iterator()); keyboardWrapper.init(); mouseWrapper.init(); controllerWrapper.init(); gestureWrapper.init(); focusWrapper.init(); expect(keyboardWrapper.getEvents()).andReturn(adau); expect(keyboardWrapper.getEvents()).andReturn(adau); expect(keyboardWrapper.getEvents()).andReturn(Iterators.peekingIterator(noKeys.iterator())); expect(keyboardWrapper.getEvents()).andReturn(Iterators.peekingIterator(noKeys.iterator())); expect(mouseWrapper.getEvents()).andReturn(Iterators.peekingIterator(noMice.iterator())).times(4); expect(controllerWrapper.getEvents()).andReturn(Iterators.peekingIterator(nothing.iterator())).times(4); expect(gestureWrapper.getEvents()).andReturn(Iterators.peekingIterator(noGestures.iterator())).times(4); expect(focusWrapper.getAndClearFocusLost()).andReturn(false).times(2); replay(mocks); pl.readState(); inputStates = pl.drainAvailableStates(); assertEquals("2 states", 2, inputStates.size()); is = inputStates.get(0); assertTrue("a down", is.getKeyboardState().isDown(Key.A)); assertFalse("b down", is.getKeyboardState().isDown(Key.B)); is = inputStates.get(1); assertFalse("a down", is.getKeyboardState().isDown(Key.A)); assertFalse("b down", is.getKeyboardState().isDown(Key.B)); pl.readState(); inputStates = pl.drainAvailableStates(); assertEquals("0 states", 0, inputStates.size()); }
@Test public void testLostFocus2() throws Exception { keyboardWrapper.init(); mouseWrapper.init(); controllerWrapper.init(); gestureWrapper.init(); focusWrapper.init(); expect(keyboardWrapper.getEvents()).andReturn(Iterators.peekingIterator(Adown.iterator())); expect(keyboardWrapper.getEvents()).andReturn(Iterators.peekingIterator(noKeys.iterator())); expect(keyboardWrapper.getEvents()).andReturn(Iterators.peekingIterator(noKeys.iterator())); expect(mouseWrapper.getEvents()).andReturn(Iterators.peekingIterator(noMice.iterator())).times(3); expect(controllerWrapper.getEvents()).andReturn(Iterators.peekingIterator(nothing.iterator())).times(3); expect(gestureWrapper.getEvents()).andReturn(Iterators.peekingIterator(noGestures.iterator())).times(3); expect(focusWrapper.getAndClearFocusLost()).andReturn(false); expect(focusWrapper.getAndClearFocusLost()).andReturn(true); replay(mocks); pl.readState(); pl.readState(); inputStates = pl.drainAvailableStates(); assertEquals("2 states", 2, inputStates.size()); is = inputStates.get(0); assertTrue("a down", is.getKeyboardState().isDown(Key.A)); assertFalse("b down", is.getKeyboardState().isDown(Key.B)); is = inputStates.get(1); assertEquals("lost focus", InputState.LOST_FOCUS, is); assertFalse("a down", is.getKeyboardState().isDown(Key.A)); assertFalse("b down", is.getKeyboardState().isDown(Key.B)); }
@Test public void testKeyboardBasic1() throws Exception { keyboardWrapper.init(); mouseWrapper.init(); controllerWrapper.init(); gestureWrapper.init(); focusWrapper.init(); expect(keyboardWrapper.getEvents()).andReturn(Iterators.peekingIterator(Adown.iterator())); expect(keyboardWrapper.getEvents()).andReturn(Iterators.peekingIterator(noKeys.iterator())); expect(keyboardWrapper.getEvents()).andReturn(Iterators.peekingIterator(noKeys.iterator())); expect(mouseWrapper.getEvents()).andReturn(Iterators.peekingIterator(noMice.iterator())).times(3); expect(controllerWrapper.getEvents()).andReturn(Iterators.peekingIterator(nothing.iterator())).times(3); expect(gestureWrapper.getEvents()).andReturn(Iterators.peekingIterator(noGestures.iterator())).times(3); expect(focusWrapper.getAndClearFocusLost()).andReturn(false).atLeastOnce(); replay(mocks); pl.readState(); inputStates = pl.drainAvailableStates(); assertEquals("1 state", 1, inputStates.size()); is = inputStates.get(0); assertTrue("a down", is.getKeyboardState().isDown(Key.A)); assertFalse("b down", is.getKeyboardState().isDown(Key.B)); pl.readState(); inputStates = pl.drainAvailableStates(); assertEquals("0 states", 0, inputStates.size()); }
@Test public void testKeyboardBasic3() throws Exception { keyboardWrapper.init(); mouseWrapper.init(); controllerWrapper.init(); gestureWrapper.init(); focusWrapper.init(); final PeekingIterator<KeyEvent> keyIterator = Iterators.peekingIterator(AdownBdown.iterator()); expect(keyboardWrapper.getEvents()).andReturn(keyIterator).times(4); expect(mouseWrapper.getEvents()).andReturn(Iterators.peekingIterator(noMice.iterator())).times(4); expect(controllerWrapper.getEvents()).andReturn(Iterators.peekingIterator(nothing.iterator())).times(4); expect(gestureWrapper.getEvents()).andReturn(Iterators.peekingIterator(noGestures.iterator())).times(4); expect(focusWrapper.getAndClearFocusLost()).andReturn(false).times(2); replay(mocks); pl.readState(); inputStates = pl.drainAvailableStates(); assertEquals("2 states", 2, inputStates.size()); is = inputStates.get(0); assertTrue("a down", is.getKeyboardState().isDown(Key.A)); assertFalse("b down", is.getKeyboardState().isDown(Key.B)); is = inputStates.get(1); assertTrue("a down", is.getKeyboardState().isDown(Key.A)); assertTrue("b down", is.getKeyboardState().isDown(Key.B)); pl.readState(); inputStates = pl.drainAvailableStates(); assertEquals("0 states", 0, inputStates.size()); }