1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 17 package com.badlogic.gdx; 18 19 import com.badlogic.gdx.Input.Buttons; 20 21 /** An InputProcessor is used to receive input events from the keyboard and the touch screen (mouse on the desktop). For this it 22 * has to be registered with the {@link Input#setInputProcessor(InputProcessor)} method. It will be called each frame before the 23 * call to {@link ApplicationListener#render()}. Each method returns a boolean in case you want to use this with the 24 * {@link InputMultiplexer} to chain input processors. 25 * 26 * @author mzechner */ 27 public interface InputProcessor { 28 /** Called when a key was pressed 29 * 30 * @param keycode one of the constants in {@link Input.Keys} 31 * @return whether the input was processed */ keyDown(int keycode)32 public boolean keyDown (int keycode); 33 34 /** Called when a key was released 35 * 36 * @param keycode one of the constants in {@link Input.Keys} 37 * @return whether the input was processed */ keyUp(int keycode)38 public boolean keyUp (int keycode); 39 40 /** Called when a key was typed 41 * 42 * @param character The character 43 * @return whether the input was processed */ keyTyped(char character)44 public boolean keyTyped (char character); 45 46 /** Called when the screen was touched or a mouse button was pressed. The button parameter will be {@link Buttons#LEFT} on iOS. 47 * @param screenX The x coordinate, origin is in the upper left corner 48 * @param screenY The y coordinate, origin is in the upper left corner 49 * @param pointer the pointer for the event. 50 * @param button the button 51 * @return whether the input was processed */ touchDown(int screenX, int screenY, int pointer, int button)52 public boolean touchDown (int screenX, int screenY, int pointer, int button); 53 54 /** Called when a finger was lifted or a mouse button was released. The button parameter will be {@link Buttons#LEFT} on iOS. 55 * @param pointer the pointer for the event. 56 * @param button the button 57 * @return whether the input was processed */ touchUp(int screenX, int screenY, int pointer, int button)58 public boolean touchUp (int screenX, int screenY, int pointer, int button); 59 60 /** Called when a finger or the mouse was dragged. 61 * @param pointer the pointer for the event. 62 * @return whether the input was processed */ touchDragged(int screenX, int screenY, int pointer)63 public boolean touchDragged (int screenX, int screenY, int pointer); 64 65 /** Called when the mouse was moved without any buttons being pressed. Will not be called on iOS. 66 * @return whether the input was processed */ mouseMoved(int screenX, int screenY)67 public boolean mouseMoved (int screenX, int screenY); 68 69 /** Called when the mouse wheel was scrolled. Will not be called on iOS. 70 * @param amount the scroll amount, -1 or 1 depending on the direction the wheel was scrolled. 71 * @return whether the input was processed. */ scrolled(int amount)72 public boolean scrolled (int amount); 73 } 74