本文整理了Java中com.ardor3d.input.KeyEvent.getState()
方法的一些代码示例,展示了KeyEvent.getState()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyEvent.getState()
方法的具体详情如下:
包路径:com.ardor3d.input.KeyEvent
类名称:KeyEvent
方法名:getState
暂无
代码示例来源:origin: com.ardor3d/ardor3d-core
private void readKeyboardState() {
final PeekingIterator<KeyEvent> eventIterator = _keyboardWrapper.getEvents();
// if no new events, just leave the current state as is
if (!eventIterator.hasNext()) {
return;
}
final KeyEvent keyEvent = eventIterator.next();
// EnumSet.copyOf fails if the collection is empty, since it needs at least one object to
// figure out which type of enum to deal with. Hence the check below.
final EnumSet<Key> keysDown = _currentKeyboardState.getKeysDown().isEmpty() ? EnumSet.noneOf(Key.class)
: EnumSet.copyOf(_currentKeyboardState.getKeysDown());
if (keyEvent.getState() == KeyState.DOWN) {
keysDown.add(keyEvent.getKey());
} else {
// ignore the fact that this removal might fail - for instance, at startup, the
// set of keys tracked as down will be empty even if somebody presses a key when the
// app starts.
keysDown.remove(keyEvent.getKey());
}
_currentKeyboardState = new KeyboardState(keysDown, keyEvent);
}
代码示例来源:origin: Renanse/Ardor3D
private void readKeyboardState() {
final PeekingIterator<KeyEvent> eventIterator = _keyboardWrapper.getEvents();
// if no new events, just leave the current state as is
if (!eventIterator.hasNext()) {
return;
}
final KeyEvent keyEvent = eventIterator.next();
// EnumSet.copyOf fails if the collection is empty, since it needs at least one object to
// figure out which type of enum to deal with. Hence the check below.
final EnumSet<Key> keysDown = _currentKeyboardState.getKeysDown().isEmpty() ? EnumSet.noneOf(Key.class)
: EnumSet.copyOf(_currentKeyboardState.getKeysDown());
if (keyEvent.getState() == KeyState.DOWN) {
keysDown.add(keyEvent.getKey());
} else {
// ignore the fact that this removal might fail - for instance, at startup, the
// set of keys tracked as down will be empty even if somebody presses a key when the
// app starts.
keysDown.remove(keyEvent.getKey());
}
_currentKeyboardState = new KeyboardState(keysDown, keyEvent);
}
代码示例来源:origin: Renanse/Ardor3D
@Test
public void testKeys2() throws Exception {
e1.keyCode = 'a';
e2.keyCode = 'b';
kw.keyPressed(e1);
kw.keyPressed(e2);
final Iterator<KeyEvent> events = kw.getEvents();
final KeyEvent event1 = events.next();
final KeyEvent event2 = events.next();
final KeyEvent event3 = events.next();
assertFalse("no more", events.hasNext());
assertFalse("no more", kw.getEvents().hasNext());
assertEquals("key a", Key.A, event1.getKey());
assertEquals("down", KeyState.DOWN, event1.getState());
assertEquals("key a", Key.A, event2.getKey());
assertEquals("up", KeyState.UP, event2.getState());
assertEquals("key b", Key.B, event3.getKey());
assertEquals("down", KeyState.DOWN, event3.getState());
}
代码示例来源:origin: Renanse/Ardor3D
@Test
public void testKeys1() throws Exception {
e1.keyCode = 'a';
kw.keyPressed(e1);
kw.keyReleased(e1);
final Iterator<KeyEvent> events = kw.getEvents();
final KeyEvent event1 = events.next();
final KeyEvent event2 = events.next();
assertFalse("no more", events.hasNext());
assertFalse("no more", kw.getEvents().hasNext());
assertEquals("key a", Key.A, event1.getKey());
assertEquals("down", KeyState.DOWN, event1.getState());
assertEquals("key a", Key.A, event2.getKey());
assertEquals("up", KeyState.UP, event2.getState());
}
代码示例来源:origin: Renanse/Ardor3D
@Test
public void testKeys1() throws Exception {
e1 = new java.awt.event.KeyEvent(control, 0, 0, 0, AwtKey.A.getAwtCode(), 'a');
kw.keyPressed(e1);
kw.keyReleased(e1);
final Iterator<KeyEvent> events = kw.getEvents();
final KeyEvent event1 = events.next();
final KeyEvent event2 = events.next();
assertFalse("no more", events.hasNext());
assertFalse("no more", kw.getEvents().hasNext());
assertEquals("key a", Key.A, event1.getKey());
assertEquals("down", KeyState.DOWN, event1.getState());
assertEquals("key a", Key.A, event2.getKey());
assertEquals("up", KeyState.UP, event2.getState());
}
代码示例来源:origin: Renanse/Ardor3D
@Test
public void testKeysRepeat() throws Exception {
e1.keyCode = 'a';
kw.keyPressed(e1);
kw.keyPressed(e1);
final Iterator<KeyEvent> events = kw.getEvents();
final KeyEvent event1 = events.next();
assertFalse("no more", events.hasNext());
assertFalse("no more", kw.getEvents().hasNext());
assertEquals("key a", Key.A, event1.getKey());
assertEquals("down", KeyState.DOWN, event1.getState());
}
代码示例来源:origin: Renanse/Ardor3D
@Test
public void testKeys2() throws Exception {
e1 = new java.awt.event.KeyEvent(control, 0, 0, 0, AwtKey.A.getAwtCode(), 'a');
e2 = new java.awt.event.KeyEvent(control, 0, 0, 0, AwtKey.B.getAwtCode(), 'b');
kw.keyPressed(e1);
kw.keyPressed(e2);
final Iterator<KeyEvent> events = kw.getEvents();
final KeyEvent event1 = events.next();
final KeyEvent event2 = events.next();
assertFalse("no more", events.hasNext());
assertFalse("no more", kw.getEvents().hasNext());
assertEquals("key a", Key.A, event1.getKey());
assertEquals("down", KeyState.DOWN, event1.getState());
assertEquals("key b", Key.B, event2.getKey());
assertEquals("down", KeyState.DOWN, event2.getState());
}
内容来源于网络,如有侵权,请联系作者删除!