本文整理汇总了Java中net.java.games.input.Event类的典型用法代码示例。如果您正苦于以下问题:Java Event类的具体用法?Java Event怎么用?Java Event使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Event类属于net.java.games.input包,在下文中一共展示了Event类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNextDeviceEvent
import net.java.games.input.Event; //导入依赖的package包/类
protected synchronized boolean getNextDeviceEvent(Event event) throws IOException {
if (!org.lwjgl.input.Keyboard.isCreated())
return false;
if (!org.lwjgl.input.Keyboard.next())
return false;
int lwjgl_key = org.lwjgl.input.Keyboard.getEventKey();
if (lwjgl_key == org.lwjgl.input.Keyboard.KEY_NONE)
return false;
Component.Identifier.Key key_id = KeyMap.map(lwjgl_key);
if (key_id == null)
return false;
Component key = getComponent(key_id);
if (key == null)
return false;
float value = org.lwjgl.input.Keyboard.getEventKeyState() ? 1 : 0;
event.set(key, value, org.lwjgl.input.Keyboard.getEventNanoseconds());
return true;
}
示例2: processPollData
import net.java.games.input.Event; //导入依赖的package包/类
@SuppressWarnings("InfiniteLoopStatement")
@Override
public void processPollData() {
Event event = new Event();
while (controller.getEventQueue().getNextEvent(event)) {
Identifier id = event.getComponent().getIdentifier();
if (id.equals(Button._7)) {
startButtonHandler.handle(event.getComponent());
} else if (id instanceof Button && container.handlersEnabled()) {
ControllerEventHandler handler = buttonsHandlerMap.get(id.getName());
if (handler != null) {
handler.handle(event.getComponent());
}
}
}
}
示例3: listenToFirstButtonPressed
import net.java.games.input.Event; //导入依赖的package包/类
private void listenToFirstButtonPressed(ControllerListenerContainer container) {
Controller controller = container.getController();
boolean buttonPressed = false;
while (!buttonPressed) {
controller.poll();
Event event = new Event();
while (controller.getEventQueue().getNextEvent(event)) {
Identifier id = event.getComponent().getIdentifier();
if (id instanceof Button) {
propertyManager.setProperty(propName, id.getName());
propertyManager.storeProperties();
buttonPressed = true;
}
}
}
}
示例4: run
import net.java.games.input.Event; //导入依赖的package包/类
@Override
public void run() {
EventDispatcher.getInstance().addListener(CloseEvent.class, this);
if (FIRST_GAMEPAD == null) {
// Couldn't find a gamepad
LOG.warning("No gamepad found. The GamepadMonitor is not going to run.");
this.running = false;
} else {
this.running = true;
}
while (this.running) {
FIRST_GAMEPAD.poll();
EventQueue queue = FIRST_GAMEPAD.getEventQueue();
// Create an event object to pass down to get populated with the information.
Event event = new Event();
while (queue.getNextEvent(event)) {
Component comp = event.getComponent();
if (!comp.isAnalog() || Math.abs(event.getValue()) > ANALOG_DEAD_ZONE) {
EventDispatcher.getInstance().fire(
new GamepadEvent(comp.getName(),
comp.isAnalog(),
event.getValue())
);
}
}
try {
Thread.sleep(30);
} catch (InterruptedException e) {
LOG.severe(e.getMessage());
}
}
EventDispatcher.getInstance().removeListener(CloseEvent.class, this);
}
示例5: isPressed
import net.java.games.input.Event; //导入依赖的package包/类
private boolean isPressed(Event event) {
Component component = event.getComponent();
if (component.isAnalog()) {
if (Math.abs(event.getValue()) > 0.2f) {
return true;
} else {
return false;
}
} else if (event.getValue() == 0) {
return false;
} else {
return true;
}
}
示例6: run
import net.java.games.input.Event; //导入依赖的package包/类
@Override
public void run() {
// TODO Auto-generated method stub
String keypressed = null;
EventQueue queue = keyboard.getEventQueue();
Event event = new Event();
while (true)
{
queue.getNextEvent(event);
System.out.println(event);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//x_axis.getPollData();
// try {
// c.putEvent(new BufferEvent("Joystick", x_axis.getPollData(), -1 ));
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// try {
// Thread.sleep(500);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
}
示例7: actionPerformed
import net.java.games.input.Event; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
JButton button = (JButton) e.getSource();
button.setEnabled(false);
Event event = new Event();
long currentTime = System.currentTimeMillis();
while (!queue.getNextEvent(event) && System.currentTimeMillis() - currentTime < 5000) {
}
Component comp = event.getComponent();
switch (e.getActionCommand()) {
case "upServo":
upServoComponent = comp;
break;
case "downServo":
downServoComponent = comp;
break;
case "rightServo":
rightServoComponent = comp;
break;
case "leftServo":
leftServoComponent = comp;
break;
case "forward":
forwardComponent = comp;
break;
case "back":
backComponent = comp;
break;
case "left":
leftComponent = comp;
break;
case "right":
rightComponent = comp;
break;
}
setLabels();
button.setEnabled(true);
}
示例8: getNextDeviceEvent
import net.java.games.input.Event; //导入依赖的package包/类
protected synchronized boolean getNextDeviceEvent(Event event) throws IOException {
if (!org.lwjgl.input.Mouse.isCreated())
return false;
while (true) {
long nanos = org.lwjgl.input.Mouse.getEventNanoseconds();
switch (event_state) {
case EVENT_X:
event_state = EVENT_Y;
int dx = org.lwjgl.input.Mouse.getEventDX();
if (dx != 0) {
event.set(getX(), dx, nanos);
return true;
}
break;
case EVENT_Y:
event_state = EVENT_WHEEL;
/* We must negate the y coord since lwjgl uses the
* OpenGL coordinate system
*/
int dy = -org.lwjgl.input.Mouse.getEventDY();
if (dy != 0) {
event.set(getY(), dy, nanos);
return true;
}
break;
case EVENT_WHEEL:
event_state = EVENT_BUTTON;
int dwheel = org.lwjgl.input.Mouse.getEventDWheel();
if (dwheel != 0) {
event.set(getWheel(), dwheel, nanos);
return true;
}
break;
case EVENT_BUTTON:
event_state = EVENT_DONE;
int lwjgl_button = org.lwjgl.input.Mouse.getEventButton();
if (lwjgl_button != -1) {
Button button = map(lwjgl_button);
if (button != null) {
event.set(button, org.lwjgl.input.Mouse.getEventButtonState() ? 1f : 0f, nanos);
return true;
}
}
break;
case EVENT_DONE:
if (!org.lwjgl.input.Mouse.next())
return false;
event_state = EVENT_X;
break;
default:
break;
}
}
}
示例9: poll
import net.java.games.input.Event; //导入依赖的package包/类
public void poll() {
target.poll();
Event event = new Event();
EventQueue queue = target.getEventQueue();
while (queue.getNextEvent(event)) {
// handle button event
if (buttons.contains(event.getComponent())) {
Component button = event.getComponent();
int buttonIndex = buttons.indexOf(button);
buttonState[buttonIndex] = event.getValue() != 0;
// fire button pressed event
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.BUTTON,buttonIndex,false,false));
}
// handle pov events
if (pov.contains(event.getComponent())) {
Component povComponent = event.getComponent();
int povIndex = pov.indexOf(povComponent);
float prevX = getPovX();
float prevY = getPovY();
povValues[povIndex] = event.getValue();
if (prevX != getPovX()) {
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.POVX,0,false,false));
}
if (prevY != getPovY()) {
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.POVY,0,false,false));
}
}
// handle axis updates
if (axes.contains(event.getComponent())) {
Component axis = event.getComponent();
int axisIndex = axes.indexOf(axis);
float value = axis.getPollData();
// fixed dead zone since most axis don't report it :(
if (Math.abs(value) < deadZones[axisIndex]) {
value = 0;
}
if (Math.abs(value) < axis.getDeadZone()) {
value = 0;
}
if (Math.abs(value) > axesMax[axisIndex]) {
axesMax[axisIndex] = Math.abs(value);
}
// normalize the value based on maximum value read in the past
value /= axesMax[axisIndex];
// fire event
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.AXIS,axisIndex,
axisIndex == xaxis,axisIndex == yaxis));
axesValue[axisIndex] = value;
}
}
}
示例10: eventQueueLoop
import net.java.games.input.Event; //导入依赖的package包/类
private Runnable eventQueueLoop() {
return new Runnable() {
@Override
public void run() {
if (gameController != null) {
Event event = new Event();
while (!Thread.interrupted()) {
gameController.poll();
EventQueue queue = gameController.getEventQueue();
while (queue.getNextEvent(event)) {
Component component = event.getComponent();
if (component.getIdentifier() == Component.Identifier.Axis.X) {
if (event.getValue() > threshold) {
gamepadbyte |= BIT7;//left on, right off
gamepadbyte &= ~BIT6;
} else if (event.getValue() < -threshold) {
gamepadbyte |= BIT6;
gamepadbyte &= ~BIT7;
} else {
gamepadbyte &= ~(BIT7 | BIT6);
}
} else if (component.getIdentifier() == Component.Identifier.Axis.Y) {
if (event.getValue() > threshold) {
gamepadbyte |= BIT5;//up on, down off
gamepadbyte &= ~BIT4;
} else if (event.getValue() < -threshold) {
gamepadbyte |= BIT4;//down on, up off
gamepadbyte &= ~BIT5;
} else {
gamepadbyte &= ~(BIT4 | BIT5);
}
} else if (component == buttons[0]) {
if (isPressed(event)) {
gamepadbyte |= BIT0;
} else {
gamepadbyte &= ~BIT0;
}
} else if (component == buttons[1]) {
if (isPressed(event)) {
gamepadbyte |= BIT1;
} else {
gamepadbyte &= ~BIT1;
}
} else if (component == buttons[2]) {
if (isPressed(event)) {
gamepadbyte |= BIT2;
} else {
gamepadbyte &= ~BIT2;
}
} else if (component == buttons[3]) {
if (isPressed(event)) {
gamepadbyte |= BIT3;
} else {
gamepadbyte &= ~BIT3;
}
}
}
try {
Thread.sleep(5);
} catch (InterruptedException e) {
// Preserve interrupt status
Thread.currentThread().interrupt();
}
}
}
}
};
}
示例11: poll
import net.java.games.input.Event; //导入依赖的package包/类
public void poll() {
target.poll();
Event event = new Event();
EventQueue queue = target.getEventQueue();
while (queue.getNextEvent(event)) {
// handle button event
if (buttons.contains(event.getComponent())) {
Component button = event.getComponent();
int buttonIndex = buttons.indexOf(button);
buttonState[buttonIndex] = event.getValue() != 0;
// fire button pressed event
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.BUTTON,buttonIndex,
buttonState[buttonIndex],false,false,0,0));
}
// handle pov events
if (pov.contains(event.getComponent())) {
Component povComponent = event.getComponent();
int povIndex = pov.indexOf(povComponent);
float prevX = getPovX();
float prevY = getPovY();
povValues[povIndex] = event.getValue();
if (prevX != getPovX()) {
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.POVX,0,false,false));
}
if (prevY != getPovY()) {
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.POVY,0,false,false));
}
}
// handle axis updates
if (axes.contains(event.getComponent())) {
Component axis = event.getComponent();
int axisIndex = axes.indexOf(axis);
float value = axis.getPollData();
float xaxisValue = 0;
float yaxisValue = 0;
// fixed dead zone since most axis don't report it :(
if (Math.abs(value) < deadZones[axisIndex]) {
value = 0;
}
if (Math.abs(value) < axis.getDeadZone()) {
value = 0;
}
if (Math.abs(value) > axesMax[axisIndex]) {
axesMax[axisIndex] = Math.abs(value);
}
// normalize the value based on maximum value read in the past
value /= axesMax[axisIndex];
if (axisIndex == xaxis) {
xaxisValue = value;
}
if (axisIndex == yaxis) {
yaxisValue = value;
}
// fire event
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.AXIS,axisIndex,false,
axisIndex == xaxis,axisIndex == yaxis,xaxisValue,yaxisValue));
axesValue[axisIndex] = value;
}
}
}
示例12: eventQueueLoop
import net.java.games.input.Event; //导入依赖的package包/类
private Runnable eventQueueLoop() {
return new Runnable() {
@Override
public void run() {
if (gameController != null) {
Event event = new Event();
while (!Thread.interrupted()) {
gameController.poll();
EventQueue queue = gameController.getEventQueue();
while (queue.getNextEvent(event)) {
Component component = event.getComponent();
if (component.getIdentifier() == Component.Identifier.Axis.X) {
if (event.getValue() > threshold) {
gamepadbyte |= BIT7;//left on, right off
gamepadbyte &= ~BIT6;
} else if (event.getValue() < -threshold) {
gamepadbyte |= BIT6;
gamepadbyte &= ~BIT7;
} else {
gamepadbyte &= ~(BIT7 | BIT6);
}
} else if (component.getIdentifier() == Component.Identifier.Axis.Y) {
if (event.getValue() > threshold) {
gamepadbyte |= BIT5;//up on, down off
gamepadbyte &= ~BIT4;
} else if (event.getValue() < -threshold) {
gamepadbyte |= BIT4;//down on, up off
gamepadbyte &= ~BIT5;
} else {
gamepadbyte &= ~(BIT4 | BIT5);
}
} else if (component == buttons[0]) {
if (isPressed(event)) {
gamepadbyte |= BIT0;
} else {
gamepadbyte &= ~BIT0;
}
} else if (component == buttons[1]) {
if (isPressed(event)) {
gamepadbyte |= BIT1;
} else {
gamepadbyte &= ~BIT1;
}
} else if (component == buttons[2]) {
if (isPressed(event)) {
gamepadbyte |= BIT2;
} else {
gamepadbyte &= ~BIT2;
}
} else if (component == buttons[3]) {
if (isPressed(event)) {
gamepadbyte |= BIT3;
} else {
gamepadbyte &= ~BIT3;
}
}
}
try {
Thread.sleep(5);
} catch (InterruptedException e) {
// Preserve interrupt status
Thread.currentThread().interrupt();
}
}
}
}
};
}
示例13: poll
import net.java.games.input.Event; //导入依赖的package包/类
public void poll() {
target.poll();
Event event = new Event();
EventQueue queue = target.getEventQueue();
while (queue.getNextEvent(event)) {
// handle button event
if (buttons.contains(event.getComponent())) {
Component button = event.getComponent();
int buttonIndex = buttons.indexOf(button);
buttonState[buttonIndex] = event.getValue() != 0;
// fire button pressed event
Controllers.addEvent(new ControllerEvent(this, event.getNanos(), ControllerEvent.BUTTON, buttonIndex,
buttonState[buttonIndex], false, false, 0, 0));
}
// handle pov events
if (pov.contains(event.getComponent())) {
Component povComponent = event.getComponent();
int povIndex = pov.indexOf(povComponent);
float prevX = getPovX();
float prevY = getPovY();
povValues[povIndex] = event.getValue();
if (prevX != getPovX()) {
Controllers.addEvent(new ControllerEvent(this, event.getNanos(), ControllerEvent.POVX, 0, false, false));
}
if (prevY != getPovY()) {
Controllers.addEvent(new ControllerEvent(this, event.getNanos(), ControllerEvent.POVY, 0, false, false));
}
}
// handle axis updates
if (axes.contains(event.getComponent())) {
Component axis = event.getComponent();
int axisIndex = axes.indexOf(axis);
float value = axis.getPollData();
float xaxisValue = 0;
float yaxisValue = 0;
// fixed dead zone since most axis don't report it :(
if (Math.abs(value) < deadZones[axisIndex]) {
value = 0;
}
if (Math.abs(value) < axis.getDeadZone()) {
value = 0;
}
if (Math.abs(value) > axesMax[axisIndex]) {
axesMax[axisIndex] = Math.abs(value);
}
// normalize the value based on maximum value read in the past
value /= axesMax[axisIndex];
if (axisIndex == xaxis) {
xaxisValue = value;
}
if (axisIndex == yaxis) {
yaxisValue = value;
}
// fire event
Controllers.addEvent(new ControllerEvent(this, event.getNanos(), ControllerEvent.AXIS, axisIndex, false,
axisIndex == xaxis, axisIndex == yaxis, xaxisValue, yaxisValue));
axesValue[axisIndex] = value;
}
}
}