private void initKeys() { // You can map one or several inputs to one named action this.inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_A)); this.inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_D)); this.inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_W)); this.inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_S)); this.inputManager.addListener(this.actionListener, "Lefts"); this.inputManager.addListener(this.actionListener, "Rights"); this.inputManager.addListener(this.actionListener, "Ups"); this.inputManager.addListener(this.actionListener, "Downs"); } private boolean left;
@Override public void onAction(String name, boolean isPressed, float tpf) { if(isPressed){ pickGamePad(getInputManager().getCursorPosition()); } } }, "mouseClick");
/** * Unregister this controller from its input manager. */ public void unregisterInput(){ if (inputManager == null) { return; } for (String s : mappings) { if (inputManager.hasMapping(s)) { inputManager.deleteMapping( s ); } } inputManager.removeListener(this); inputManager.setCursorVisible(!dragToRotate); Joystick[] joysticks = inputManager.getJoysticks(); if (joysticks != null && joysticks.length > 0){ // No way to unassign axis } }
/** * Sets custom triggers for zooming in the cam * default is * new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel up * @param triggers */ public void setZoomInTrigger(Trigger... triggers) { inputManager.deleteMapping(CameraInput.CHASECAM_ZOOMIN); inputManager.addMapping(CameraInput.CHASECAM_ZOOMIN, triggers); inputManager.addListener(this, CameraInput.CHASECAM_ZOOMIN); }
/** * Cleans up the input mappings from the input manager. * Undoes the work of registerWithInput(). * @param inputManager InputManager from which to cleanup mappings. */ public void cleanupWithInput(InputManager mgr){ mgr.deleteMapping(CameraInput.CHASECAM_TOGGLEROTATE); mgr.deleteMapping(CameraInput.CHASECAM_DOWN); mgr.deleteMapping(CameraInput.CHASECAM_UP); mgr.deleteMapping(CameraInput.CHASECAM_MOVELEFT); mgr.deleteMapping(CameraInput.CHASECAM_MOVERIGHT); mgr.deleteMapping(CameraInput.CHASECAM_ZOOMIN); mgr.deleteMapping(CameraInput.CHASECAM_ZOOMOUT); mgr.removeListener(this); }
@Override public void cleanup() { super.cleanup(); if (inputManager.hasMapping(INPUT_MAPPING_CAMERA_POS)) inputManager.deleteMapping(INPUT_MAPPING_CAMERA_POS); if (inputManager.hasMapping(INPUT_MAPPING_MEMORY)) inputManager.deleteMapping(INPUT_MAPPING_MEMORY); inputManager.removeListener(keyListener); }
inputManager.addMapping(CameraInput.FLYCAM_LEFT, new MouseAxisTrigger(MouseInput.AXIS_X, true), new KeyTrigger(KeyInput.KEY_LEFT)); inputManager.addMapping(CameraInput.FLYCAM_RIGHT, new MouseAxisTrigger(MouseInput.AXIS_X, false), new KeyTrigger(KeyInput.KEY_RIGHT)); inputManager.addMapping(CameraInput.FLYCAM_UP, new MouseAxisTrigger(MouseInput.AXIS_Y, false), new KeyTrigger(KeyInput.KEY_UP)); inputManager.addMapping(CameraInput.FLYCAM_DOWN, new MouseAxisTrigger(MouseInput.AXIS_Y, true), new KeyTrigger(KeyInput.KEY_DOWN)); inputManager.addMapping(CameraInput.FLYCAM_ZOOMIN, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false)); inputManager.addMapping(CameraInput.FLYCAM_ZOOMOUT, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true)); inputManager.addMapping(CameraInput.FLYCAM_ROTATEDRAG, new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); inputManager.addMapping(CameraInput.FLYCAM_STRAFELEFT, new KeyTrigger(KeyInput.KEY_A)); inputManager.addMapping(CameraInput.FLYCAM_STRAFERIGHT, new KeyTrigger(KeyInput.KEY_D)); inputManager.addMapping(CameraInput.FLYCAM_FORWARD, new KeyTrigger(KeyInput.KEY_W)); inputManager.addMapping(CameraInput.FLYCAM_BACKWARD, new KeyTrigger(KeyInput.KEY_S)); inputManager.addMapping(CameraInput.FLYCAM_RISE, new KeyTrigger(KeyInput.KEY_Q)); inputManager.addMapping(CameraInput.FLYCAM_LOWER, new KeyTrigger(KeyInput.KEY_Z)); inputManager.addListener(this, mappings); inputManager.setCursorVisible(dragToRotate || !isEnabled()); Joystick[] joysticks = inputManager.getJoysticks(); if (joysticks != null && joysticks.length > 0){ for (Joystick j : joysticks) {
public void initialize() { app.initialize(); if (handleExitHook) { // remove existing mapping from SimpleApplication that stops the app // when the esc key is pressed (esc key = android back key) so that // AndroidHarness can produce the exit app dialog box. if (app.getInputManager().hasMapping(SimpleApplication.INPUT_MAPPING_EXIT)) { app.getInputManager().deleteMapping(SimpleApplication.INPUT_MAPPING_EXIT); } app.getInputManager().addMapping(ESCAPE_EVENT, new TouchTrigger(TouchInput.KEYCODE_BACK)); app.getInputManager().addListener(this, new String[]{ESCAPE_EVENT}); } }
@Override public void simpleInitApp() { inputManager.setCursorVisible(true); inputManager.addMapping("overrideClear", new KeyTrigger(KeyInput.KEY_SPACE)); inputManager.addMapping("overrideGray", new KeyTrigger(KeyInput.KEY_G)); inputManager.addMapping("overrideWhite", new KeyTrigger(KeyInput.KEY_W)); inputManager.addMapping("overrideYellow", new KeyTrigger(KeyInput.KEY_Y)); inputManager.addListener(new ActionListener() { @Override public void onAction(String name, boolean isPressed, float tpf) {
getFlyByCamera().setEnabled(false); Joystick[] joysticks = inputManager.getJoysticks(); if (joysticks == null) throw new IllegalStateException("Cannot find any joysticks!"); inputManager.addRawInputListener( new JoystickEventListener() ); inputManager.addMapping("mouseClick", new MouseButtonTrigger(mouseInput.BUTTON_LEFT)); inputManager.addListener(new ActionListener() { @Override public void onAction(String name, boolean isPressed, float tpf) {
/** * invert the vertical axis movement of the mouse * * @param invertYaxis */ public void setInvertVerticalAxis(boolean invertYaxis) { this.invertYaxis = invertYaxis; if (inputManager != null) { inputManager.deleteMapping(CameraInput.CHASECAM_DOWN); inputManager.deleteMapping(CameraInput.CHASECAM_UP); initVerticalAxisInputs(); inputManager.addListener(this, CameraInput.CHASECAM_DOWN, CameraInput.CHASECAM_UP); } }
/** * @param dragToRotate When true, the user must hold the mouse button * and drag over the screen to rotate the camera, and the cursor is * visible until dragged. Otherwise, the cursor is invisible at all times * and holding the mouse button is not needed to rotate the camera. * This feature is disabled by default. */ public void setDragToRotate(boolean dragToRotate) { this.dragToRotate = dragToRotate; this.canRotate = !dragToRotate; inputManager.setCursorVisible(dragToRotate); }
/** * Registers inputs with the input manager * */ public final void registerWithInput() { String[] inputs = {CameraInput.CHASECAM_TOGGLEROTATE, CameraInput.CHASECAM_DOWN, CameraInput.CHASECAM_UP, CameraInput.CHASECAM_MOVELEFT, CameraInput.CHASECAM_MOVERIGHT, CameraInput.CHASECAM_ZOOMIN, CameraInput.CHASECAM_ZOOMOUT}; initVerticalAxisInputs(); initZoomInput(); initHorizontalAxisInput(); initTogleRotateInput(); inputManager.addListener(this, inputs); inputManager.setCursorVisible(dragToRotate); }
private void initVerticalAxisInputs() { if (!invertYaxis) { inputManager.addMapping(CameraInput.CHASECAM_DOWN, new MouseAxisTrigger(MouseInput.AXIS_Y, true)); inputManager.addMapping(CameraInput.CHASECAM_UP, new MouseAxisTrigger(MouseInput.AXIS_Y, false)); } else { inputManager.addMapping(CameraInput.CHASECAM_DOWN, new MouseAxisTrigger(MouseInput.AXIS_Y, false)); inputManager.addMapping(CameraInput.CHASECAM_UP, new MouseAxisTrigger(MouseInput.AXIS_Y, true)); } }
/** * Do not call manually. * Callback from ContextListener. */ public void update(){ // Make sure the audio renderer is available to callables AudioContext.setAudioRenderer(audioRenderer); if (prof!=null) prof.appStep(AppStep.QueuedTasks); runQueuedTasks(); if (speed == 0 || paused) return; timer.update(); if (inputEnabled){ if (prof!=null) prof.appStep(AppStep.ProcessInput); inputManager.update(timer.getTimePerFrame()); } if (audioRenderer != null){ if (prof!=null) prof.appStep(AppStep.ProcessAudio); audioRenderer.update(timer.getTimePerFrame()); } // user code here.. }
@Override public void simpleInitApp() { flyCam.setEnabled(false); // We need the cursor to be visible. If it is not visible the cursor // will still be "used" and loaded, you just won't see it on the screen. inputManager.setCursorVisible(true); /* * To make jME3 use a custom cursor it is as simple as putting the * .cur/.ico/.ani file in an asset directory. Here we use * "Textures/GUI/Cursors". * * For the purpose of this demonstration we load 3 different cursors and add them * into an array list and switch cursor every 8 seconds. * * The first ico has been made by Sirea and the set can be found here: * http://www.rw-designer.com/icon-set/nyan-cat * * The second cursor has been made by Virum64 and is Public Domain. * http://www.rw-designer.com/cursor-set/memes-faces-v64 * * The animated cursor has been made by Pointer Adic and can be found here: * http://www.rw-designer.com/cursor-set/monkey */ cursors.add((JmeCursor) assetManager.loadAsset("Textures/Cursors/meme.cur")); cursors.add((JmeCursor) assetManager.loadAsset("Textures/Cursors/nyancat.ico")); cursors.add((JmeCursor) assetManager.loadAsset("Textures/Cursors/monkey.ani")); sysTime = System.currentTimeMillis(); inputManager.setMouseCursor(cursors.get(count)); }
public InputMapper( InputManager inputManager ) { this.inputManager = inputManager; this.listener = new InputObserver(); inputManager.addRawInputListener(listener); Joystick[] sticks = inputManager.getJoysticks(); if( sticks != null ) { for( Joystick j : sticks ) { mapJoystick(j); } } // The default group always starts active. activeGroups.add(FunctionId.DEFAULT_GROUP); lastFrameNanos = System.nanoTime(); }
/** * Initializes mouse and keyboard input. Also * initializes joystick input if joysticks are enabled in the * AppSettings. */ private void initInput(){ mouseInput = context.getMouseInput(); if (mouseInput != null) mouseInput.initialize(); keyInput = context.getKeyInput(); if (keyInput != null) keyInput.initialize(); touchInput = context.getTouchInput(); if (touchInput != null) touchInput.initialize(); if (!settings.getBoolean("DisableJoysticks")){ joyInput = context.getJoyInput(); if (joyInput != null) joyInput.initialize(); } inputManager = new InputManager(mouseInput, keyInput, joyInput, touchInput); }
/** * Sets custom triggers for toggling the rotation of the cam * default are * new MouseButtonTrigger(MouseInput.BUTTON_LEFT) left mouse button * new MouseButtonTrigger(MouseInput.BUTTON_RIGHT) right mouse button * @param triggers */ public void setToggleRotationTrigger(Trigger... triggers) { inputManager.deleteMapping(CameraInput.CHASECAM_TOGGLEROTATE); inputManager.addMapping(CameraInput.CHASECAM_TOGGLEROTATE, triggers); inputManager.addListener(this, CameraInput.CHASECAM_TOGGLEROTATE); }
inputManager.addMapping(CameraInput.FLYCAM_LEFT, new MouseAxisTrigger(MouseInput.AXIS_X, true), new KeyTrigger(KeyInput.KEY_LEFT)); inputManager.addMapping(CameraInput.FLYCAM_RIGHT, new MouseAxisTrigger(MouseInput.AXIS_X, false), new KeyTrigger(KeyInput.KEY_RIGHT)); inputManager.addMapping(CameraInput.FLYCAM_UP, new MouseAxisTrigger(MouseInput.AXIS_Y, false), new KeyTrigger(KeyInput.KEY_UP)); inputManager.addMapping(CameraInput.FLYCAM_DOWN, new MouseAxisTrigger(MouseInput.AXIS_Y, true), new KeyTrigger(KeyInput.KEY_DOWN)); inputManager.addMapping(CameraInput.FLYCAM_ZOOMIN, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false)); inputManager.addMapping(CameraInput.FLYCAM_ZOOMOUT, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true)); inputManager.addMapping(CameraInput.FLYCAM_ROTATEDRAG, new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); inputManager.addMapping(CameraInput.FLYCAM_STRAFELEFT, new KeyTrigger(KeyInput.KEY_A)); inputManager.addMapping(CameraInput.FLYCAM_STRAFERIGHT, new KeyTrigger(KeyInput.KEY_D)); inputManager.addMapping(CameraInput.FLYCAM_FORWARD, new KeyTrigger(KeyInput.KEY_W)); inputManager.addMapping(CameraInput.FLYCAM_BACKWARD, new KeyTrigger(KeyInput.KEY_S)); inputManager.addMapping(CameraInput.FLYCAM_RISE, new KeyTrigger(KeyInput.KEY_Q)); inputManager.addMapping(CameraInput.FLYCAM_LOWER, new KeyTrigger(KeyInput.KEY_Z)); inputManager.addListener(this, mappings); inputManager.setCursorVisible(dragToRotate || !isEnabled()); Joystick[] joysticks = inputManager.getJoysticks(); if (joysticks != null && joysticks.length > 0){ for (Joystick j : joysticks) {