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.graphics.Pixmap; 20 import com.badlogic.gdx.utils.ObjectIntMap; 21 22 /** <p> 23 * Interface to the input facilities. This allows polling the state of the keyboard, the touch screen and the accelerometer. On 24 * some backends (desktop, gwt, etc) the touch screen is replaced by mouse input. The accelerometer is of course not available on 25 * all backends. 26 * </p> 27 * 28 * <p> 29 * Instead of polling for events, one can process all input events with an {@link InputProcessor}. You can set the InputProcessor 30 * via the {@link #setInputProcessor(InputProcessor)} method. It will be called before the {@link ApplicationListener#render()} 31 * method in each frame. 32 * </p> 33 * 34 * <p> 35 * Keyboard keys are translated to the constants in {@link Keys} transparently on all systems. Do not use system specific key 36 * constants. 37 * </p> 38 * 39 * <p> 40 * The class also offers methods to use (and test for the presence of) other input systems like vibration, compass, on-screen 41 * keyboards, and cursor capture. Support for simple input dialogs is also provided. 42 * </p> 43 * 44 * @author mzechner */ 45 public interface Input { 46 /** Callback interface for {@link Input#getTextInput(TextInputListener, String, String, String)} 47 * 48 * @author mzechner */ 49 static public interface TextInputListener { input(String text)50 public void input (String text); 51 canceled()52 public void canceled (); 53 } 54 55 /** Mouse buttons. 56 * @author mzechner */ 57 static public class Buttons { 58 public static final int LEFT = 0; 59 public static final int RIGHT = 1; 60 public static final int MIDDLE = 2; 61 public static final int BACK = 3; 62 public static final int FORWARD = 4; 63 } 64 65 /** Keys. 66 * 67 * @author mzechner */ 68 static public class Keys { 69 public static final int ANY_KEY = -1; 70 public static final int NUM_0 = 7; 71 public static final int NUM_1 = 8; 72 public static final int NUM_2 = 9; 73 public static final int NUM_3 = 10; 74 public static final int NUM_4 = 11; 75 public static final int NUM_5 = 12; 76 public static final int NUM_6 = 13; 77 public static final int NUM_7 = 14; 78 public static final int NUM_8 = 15; 79 public static final int NUM_9 = 16; 80 public static final int A = 29; 81 public static final int ALT_LEFT = 57; 82 public static final int ALT_RIGHT = 58; 83 public static final int APOSTROPHE = 75; 84 public static final int AT = 77; 85 public static final int B = 30; 86 public static final int BACK = 4; 87 public static final int BACKSLASH = 73; 88 public static final int C = 31; 89 public static final int CALL = 5; 90 public static final int CAMERA = 27; 91 public static final int CLEAR = 28; 92 public static final int COMMA = 55; 93 public static final int D = 32; 94 public static final int DEL = 67; 95 public static final int BACKSPACE = 67; 96 public static final int FORWARD_DEL = 112; 97 public static final int DPAD_CENTER = 23; 98 public static final int DPAD_DOWN = 20; 99 public static final int DPAD_LEFT = 21; 100 public static final int DPAD_RIGHT = 22; 101 public static final int DPAD_UP = 19; 102 public static final int CENTER = 23; 103 public static final int DOWN = 20; 104 public static final int LEFT = 21; 105 public static final int RIGHT = 22; 106 public static final int UP = 19; 107 public static final int E = 33; 108 public static final int ENDCALL = 6; 109 public static final int ENTER = 66; 110 public static final int ENVELOPE = 65; 111 public static final int EQUALS = 70; 112 public static final int EXPLORER = 64; 113 public static final int F = 34; 114 public static final int FOCUS = 80; 115 public static final int G = 35; 116 public static final int GRAVE = 68; 117 public static final int H = 36; 118 public static final int HEADSETHOOK = 79; 119 public static final int HOME = 3; 120 public static final int I = 37; 121 public static final int J = 38; 122 public static final int K = 39; 123 public static final int L = 40; 124 public static final int LEFT_BRACKET = 71; 125 public static final int M = 41; 126 public static final int MEDIA_FAST_FORWARD = 90; 127 public static final int MEDIA_NEXT = 87; 128 public static final int MEDIA_PLAY_PAUSE = 85; 129 public static final int MEDIA_PREVIOUS = 88; 130 public static final int MEDIA_REWIND = 89; 131 public static final int MEDIA_STOP = 86; 132 public static final int MENU = 82; 133 public static final int MINUS = 69; 134 public static final int MUTE = 91; 135 public static final int N = 42; 136 public static final int NOTIFICATION = 83; 137 public static final int NUM = 78; 138 public static final int O = 43; 139 public static final int P = 44; 140 public static final int PERIOD = 56; 141 public static final int PLUS = 81; 142 public static final int POUND = 18; 143 public static final int POWER = 26; 144 public static final int Q = 45; 145 public static final int R = 46; 146 public static final int RIGHT_BRACKET = 72; 147 public static final int S = 47; 148 public static final int SEARCH = 84; 149 public static final int SEMICOLON = 74; 150 public static final int SHIFT_LEFT = 59; 151 public static final int SHIFT_RIGHT = 60; 152 public static final int SLASH = 76; 153 public static final int SOFT_LEFT = 1; 154 public static final int SOFT_RIGHT = 2; 155 public static final int SPACE = 62; 156 public static final int STAR = 17; 157 public static final int SYM = 63; 158 public static final int T = 48; 159 public static final int TAB = 61; 160 public static final int U = 49; 161 public static final int UNKNOWN = 0; 162 public static final int V = 50; 163 public static final int VOLUME_DOWN = 25; 164 public static final int VOLUME_UP = 24; 165 public static final int W = 51; 166 public static final int X = 52; 167 public static final int Y = 53; 168 public static final int Z = 54; 169 public static final int META_ALT_LEFT_ON = 16; 170 public static final int META_ALT_ON = 2; 171 public static final int META_ALT_RIGHT_ON = 32; 172 public static final int META_SHIFT_LEFT_ON = 64; 173 public static final int META_SHIFT_ON = 1; 174 public static final int META_SHIFT_RIGHT_ON = 128; 175 public static final int META_SYM_ON = 4; 176 public static final int CONTROL_LEFT = 129; 177 public static final int CONTROL_RIGHT = 130; 178 public static final int ESCAPE = 131; 179 public static final int END = 132; 180 public static final int INSERT = 133; 181 public static final int PAGE_UP = 92; 182 public static final int PAGE_DOWN = 93; 183 public static final int PICTSYMBOLS = 94; 184 public static final int SWITCH_CHARSET = 95; 185 public static final int BUTTON_CIRCLE = 255; 186 public static final int BUTTON_A = 96; 187 public static final int BUTTON_B = 97; 188 public static final int BUTTON_C = 98; 189 public static final int BUTTON_X = 99; 190 public static final int BUTTON_Y = 100; 191 public static final int BUTTON_Z = 101; 192 public static final int BUTTON_L1 = 102; 193 public static final int BUTTON_R1 = 103; 194 public static final int BUTTON_L2 = 104; 195 public static final int BUTTON_R2 = 105; 196 public static final int BUTTON_THUMBL = 106; 197 public static final int BUTTON_THUMBR = 107; 198 public static final int BUTTON_START = 108; 199 public static final int BUTTON_SELECT = 109; 200 public static final int BUTTON_MODE = 110; 201 202 public static final int NUMPAD_0 = 144; 203 public static final int NUMPAD_1 = 145; 204 public static final int NUMPAD_2 = 146; 205 public static final int NUMPAD_3 = 147; 206 public static final int NUMPAD_4 = 148; 207 public static final int NUMPAD_5 = 149; 208 public static final int NUMPAD_6 = 150; 209 public static final int NUMPAD_7 = 151; 210 public static final int NUMPAD_8 = 152; 211 public static final int NUMPAD_9 = 153; 212 213 // public static final int BACKTICK = 0; 214 // public static final int TILDE = 0; 215 // public static final int UNDERSCORE = 0; 216 // public static final int DOT = 0; 217 // public static final int BREAK = 0; 218 // public static final int PIPE = 0; 219 // public static final int EXCLAMATION = 0; 220 // public static final int QUESTIONMARK = 0; 221 222 // ` | VK_BACKTICK 223 // ~ | VK_TILDE 224 // : | VK_COLON 225 // _ | VK_UNDERSCORE 226 // . | VK_DOT 227 // (break) | VK_BREAK 228 // | | VK_PIPE 229 // ! | VK_EXCLAMATION 230 // ? | VK_QUESTION 231 public static final int COLON = 243; 232 public static final int F1 = 244; 233 public static final int F2 = 245; 234 public static final int F3 = 246; 235 public static final int F4 = 247; 236 public static final int F5 = 248; 237 public static final int F6 = 249; 238 public static final int F7 = 250; 239 public static final int F8 = 251; 240 public static final int F9 = 252; 241 public static final int F10 = 253; 242 public static final int F11 = 254; 243 public static final int F12 = 255; 244 245 /** @return a human readable representation of the keycode. The returned value can be used in 246 * {@link Input.Keys#valueOf(String)} */ toString(int keycode)247 public static String toString (int keycode) { 248 if (keycode < 0) throw new IllegalArgumentException("keycode cannot be negative, keycode: " + keycode); 249 if (keycode > 255) throw new IllegalArgumentException("keycode cannot be greater than 255, keycode: " + keycode); 250 switch (keycode) { 251 // META* variables should not be used with this method. 252 case UNKNOWN: 253 return "Unknown"; 254 case SOFT_LEFT: 255 return "Soft Left"; 256 case SOFT_RIGHT: 257 return "Soft Right"; 258 case HOME: 259 return "Home"; 260 case BACK: 261 return "Back"; 262 case CALL: 263 return "Call"; 264 case ENDCALL: 265 return "End Call"; 266 case NUM_0: 267 return "0"; 268 case NUM_1: 269 return "1"; 270 case NUM_2: 271 return "2"; 272 case NUM_3: 273 return "3"; 274 case NUM_4: 275 return "4"; 276 case NUM_5: 277 return "5"; 278 case NUM_6: 279 return "6"; 280 case NUM_7: 281 return "7"; 282 case NUM_8: 283 return "8"; 284 case NUM_9: 285 return "9"; 286 case STAR: 287 return "*"; 288 case POUND: 289 return "#"; 290 case UP: 291 return "Up"; 292 case DOWN: 293 return "Down"; 294 case LEFT: 295 return "Left"; 296 case RIGHT: 297 return "Right"; 298 case CENTER: 299 return "Center"; 300 case VOLUME_UP: 301 return "Volume Up"; 302 case VOLUME_DOWN: 303 return "Volume Down"; 304 case POWER: 305 return "Power"; 306 case CAMERA: 307 return "Camera"; 308 case CLEAR: 309 return "Clear"; 310 case A: 311 return "A"; 312 case B: 313 return "B"; 314 case C: 315 return "C"; 316 case D: 317 return "D"; 318 case E: 319 return "E"; 320 case F: 321 return "F"; 322 case G: 323 return "G"; 324 case H: 325 return "H"; 326 case I: 327 return "I"; 328 case J: 329 return "J"; 330 case K: 331 return "K"; 332 case L: 333 return "L"; 334 case M: 335 return "M"; 336 case N: 337 return "N"; 338 case O: 339 return "O"; 340 case P: 341 return "P"; 342 case Q: 343 return "Q"; 344 case R: 345 return "R"; 346 case S: 347 return "S"; 348 case T: 349 return "T"; 350 case U: 351 return "U"; 352 case V: 353 return "V"; 354 case W: 355 return "W"; 356 case X: 357 return "X"; 358 case Y: 359 return "Y"; 360 case Z: 361 return "Z"; 362 case COMMA: 363 return ","; 364 case PERIOD: 365 return "."; 366 case ALT_LEFT: 367 return "L-Alt"; 368 case ALT_RIGHT: 369 return "R-Alt"; 370 case SHIFT_LEFT: 371 return "L-Shift"; 372 case SHIFT_RIGHT: 373 return "R-Shift"; 374 case TAB: 375 return "Tab"; 376 case SPACE: 377 return "Space"; 378 case SYM: 379 return "SYM"; 380 case EXPLORER: 381 return "Explorer"; 382 case ENVELOPE: 383 return "Envelope"; 384 case ENTER: 385 return "Enter"; 386 case DEL: 387 return "Delete"; // also BACKSPACE 388 case GRAVE: 389 return "`"; 390 case MINUS: 391 return "-"; 392 case EQUALS: 393 return "="; 394 case LEFT_BRACKET: 395 return "["; 396 case RIGHT_BRACKET: 397 return "]"; 398 case BACKSLASH: 399 return "\\"; 400 case SEMICOLON: 401 return ";"; 402 case APOSTROPHE: 403 return "'"; 404 case SLASH: 405 return "/"; 406 case AT: 407 return "@"; 408 case NUM: 409 return "Num"; 410 case HEADSETHOOK: 411 return "Headset Hook"; 412 case FOCUS: 413 return "Focus"; 414 case PLUS: 415 return "Plus"; 416 case MENU: 417 return "Menu"; 418 case NOTIFICATION: 419 return "Notification"; 420 case SEARCH: 421 return "Search"; 422 case MEDIA_PLAY_PAUSE: 423 return "Play/Pause"; 424 case MEDIA_STOP: 425 return "Stop Media"; 426 case MEDIA_NEXT: 427 return "Next Media"; 428 case MEDIA_PREVIOUS: 429 return "Prev Media"; 430 case MEDIA_REWIND: 431 return "Rewind"; 432 case MEDIA_FAST_FORWARD: 433 return "Fast Forward"; 434 case MUTE: 435 return "Mute"; 436 case PAGE_UP: 437 return "Page Up"; 438 case PAGE_DOWN: 439 return "Page Down"; 440 case PICTSYMBOLS: 441 return "PICTSYMBOLS"; 442 case SWITCH_CHARSET: 443 return "SWITCH_CHARSET"; 444 case BUTTON_A: 445 return "A Button"; 446 case BUTTON_B: 447 return "B Button"; 448 case BUTTON_C: 449 return "C Button"; 450 case BUTTON_X: 451 return "X Button"; 452 case BUTTON_Y: 453 return "Y Button"; 454 case BUTTON_Z: 455 return "Z Button"; 456 case BUTTON_L1: 457 return "L1 Button"; 458 case BUTTON_R1: 459 return "R1 Button"; 460 case BUTTON_L2: 461 return "L2 Button"; 462 case BUTTON_R2: 463 return "R2 Button"; 464 case BUTTON_THUMBL: 465 return "Left Thumb"; 466 case BUTTON_THUMBR: 467 return "Right Thumb"; 468 case BUTTON_START: 469 return "Start"; 470 case BUTTON_SELECT: 471 return "Select"; 472 case BUTTON_MODE: 473 return "Button Mode"; 474 case FORWARD_DEL: 475 return "Forward Delete"; 476 case CONTROL_LEFT: 477 return "L-Ctrl"; 478 case CONTROL_RIGHT: 479 return "R-Ctrl"; 480 case ESCAPE: 481 return "Escape"; 482 case END: 483 return "End"; 484 case INSERT: 485 return "Insert"; 486 case NUMPAD_0: 487 return "Numpad 0"; 488 case NUMPAD_1: 489 return "Numpad 1"; 490 case NUMPAD_2: 491 return "Numpad 2"; 492 case NUMPAD_3: 493 return "Numpad 3"; 494 case NUMPAD_4: 495 return "Numpad 4"; 496 case NUMPAD_5: 497 return "Numpad 5"; 498 case NUMPAD_6: 499 return "Numpad 6"; 500 case NUMPAD_7: 501 return "Numpad 7"; 502 case NUMPAD_8: 503 return "Numpad 8"; 504 case NUMPAD_9: 505 return "Numpad 9"; 506 case COLON: 507 return ":"; 508 case F1: 509 return "F1"; 510 case F2: 511 return "F2"; 512 case F3: 513 return "F3"; 514 case F4: 515 return "F4"; 516 case F5: 517 return "F5"; 518 case F6: 519 return "F6"; 520 case F7: 521 return "F7"; 522 case F8: 523 return "F8"; 524 case F9: 525 return "F9"; 526 case F10: 527 return "F10"; 528 case F11: 529 return "F11"; 530 case F12: 531 return "F12"; 532 // BUTTON_CIRCLE unhandled, as it conflicts with the more likely to be pressed F12 533 default: 534 // key name not found 535 return null; 536 } 537 } 538 539 private static ObjectIntMap<String> keyNames; 540 541 /** @param keyname the keyname returned by the {@link Keys#toString(int)} method 542 * @return the int keycode */ valueOf(String keyname)543 public static int valueOf (String keyname) { 544 if (keyNames == null) initializeKeyNames(); 545 return keyNames.get(keyname, -1); 546 } 547 548 /** lazily intialized in {@link Keys#valueOf(String)} */ initializeKeyNames()549 private static void initializeKeyNames () { 550 keyNames = new ObjectIntMap<String>(); 551 for (int i = 0; i < 256; i++) { 552 String name = toString(i); 553 if (name != null) keyNames.put(name, i); 554 } 555 } 556 } 557 558 /** Enumeration of potentially available peripherals. Use with {@link Input#isPeripheralAvailable(Peripheral)}. 559 * @author mzechner */ 560 public enum Peripheral { 561 HardwareKeyboard, OnscreenKeyboard, MultitouchScreen, Accelerometer, Compass, Vibrator, Gyroscope 562 } 563 564 /** @return The rate of rotation around the x axis. (rad/s) */ getAccelerometerX()565 public float getAccelerometerX (); 566 567 /** @return The rate of rotation around the y axis. (rad/s) */ getAccelerometerY()568 public float getAccelerometerY (); 569 570 /** @return The rate of rotation around the z axis. (rad/s) */ getAccelerometerZ()571 public float getAccelerometerZ (); 572 getGyroscopeX()573 public float getGyroscopeX (); 574 getGyroscopeY()575 public float getGyroscopeY (); 576 getGyroscopeZ()577 public float getGyroscopeZ (); 578 579 /** @return The x coordinate of the last touch on touch screen devices and the current mouse position on desktop for the first 580 * pointer in screen coordinates. The screen origin is the top left corner. */ getX()581 public int getX (); 582 583 /** Returns the x coordinate in screen coordinates of the given pointer. Pointers are indexed from 0 to n. The pointer id 584 * identifies the order in which the fingers went down on the screen, e.g. 0 is the first finger, 1 is the second and so on. 585 * When two fingers are touched down and the first one is lifted the second one keeps its index. If another finger is placed on 586 * the touch screen the first free index will be used. 587 * 588 * @param pointer the pointer id. 589 * @return the x coordinate */ getX(int pointer)590 public int getX (int pointer); 591 592 /** @return the different between the current pointer location and the last pointer location on the x-axis. */ getDeltaX()593 public int getDeltaX (); 594 595 /** @return the different between the current pointer location and the last pointer location on the x-axis. */ getDeltaX(int pointer)596 public int getDeltaX (int pointer); 597 598 /** @return The y coordinate of the last touch on touch screen devices and the current mouse position on desktop for the first 599 * pointer in screen coordinates. The screen origin is the top left corner. */ getY()600 public int getY (); 601 602 /** Returns the y coordinate in screen coordinates of the given pointer. Pointers are indexed from 0 to n. The pointer id 603 * identifies the order in which the fingers went down on the screen, e.g. 0 is the first finger, 1 is the second and so on. 604 * When two fingers are touched down and the first one is lifted the second one keeps its index. If another finger is placed on 605 * the touch screen the first free index will be used. 606 * 607 * @param pointer the pointer id. 608 * @return the y coordinate */ getY(int pointer)609 public int getY (int pointer); 610 611 /** @return the different between the current pointer location and the last pointer location on the y-axis. */ getDeltaY()612 public int getDeltaY (); 613 614 /** @return the different between the current pointer location and the last pointer location on the y-axis. */ getDeltaY(int pointer)615 public int getDeltaY (int pointer); 616 617 /** @return whether the screen is currently touched. */ isTouched()618 public boolean isTouched (); 619 620 /** @return whether a new touch down event just occurred. */ justTouched()621 public boolean justTouched (); 622 623 /** Whether the screen is currently touched by the pointer with the given index. Pointers are indexed from 0 to n. The pointer 624 * id identifies the order in which the fingers went down on the screen, e.g. 0 is the first finger, 1 is the second and so on. 625 * When two fingers are touched down and the first one is lifted the second one keeps its index. If another finger is placed on 626 * the touch screen the first free index will be used. 627 * 628 * @param pointer the pointer 629 * @return whether the screen is touched by the pointer */ isTouched(int pointer)630 public boolean isTouched (int pointer); 631 632 /** Whether a given button is pressed or not. Button constants can be found in {@link Buttons}. On Android only the Button#LEFT 633 * constant is meaningful before version 4.0. 634 * @param button the button to check. 635 * @return whether the button is down or not. */ isButtonPressed(int button)636 public boolean isButtonPressed (int button); 637 638 /** Returns whether the key is pressed. 639 * 640 * @param key The key code as found in {@link Input.Keys}. 641 * @return true or false. */ isKeyPressed(int key)642 public boolean isKeyPressed (int key); 643 644 /** Returns whether the key has just been pressed. 645 * 646 * @param key The key code as found in {@link Input.Keys}. 647 * @return true or false. */ isKeyJustPressed(int key)648 public boolean isKeyJustPressed (int key); 649 650 /** System dependent method to input a string of text. A dialog box will be created with the given title and the given text as a 651 * message for the user. Once the dialog has been closed the provided {@link TextInputListener} will be called on the rendering 652 * thread. 653 * 654 * @param listener The TextInputListener. 655 * @param title The title of the text input dialog. 656 * @param text The message presented to the user. */ getTextInput(TextInputListener listener, String title, String text, String hint)657 public void getTextInput (TextInputListener listener, String title, String text, String hint); 658 659 /** Sets the on-screen keyboard visible if available. 660 * 661 * @param visible visible or not */ setOnscreenKeyboardVisible(boolean visible)662 public void setOnscreenKeyboardVisible (boolean visible); 663 664 /** Vibrates for the given amount of time. Note that you'll need the permission 665 * <code> <uses-permission android:name="android.permission.VIBRATE" /></code> in your manifest file in order for this to work. 666 * 667 * @param milliseconds the number of milliseconds to vibrate. */ vibrate(int milliseconds)668 public void vibrate (int milliseconds); 669 670 /** Vibrate with a given pattern. Pass in an array of ints that are the times at which to turn on or off the vibrator. The first 671 * one is how long to wait before turning it on, and then after that it alternates. If you want to repeat, pass the index into 672 * the pattern at which to start the repeat. 673 * @param pattern an array of longs of times to turn the vibrator on or off. 674 * @param repeat the index into pattern at which to repeat, or -1 if you don't want to repeat. */ vibrate(long[] pattern, int repeat)675 public void vibrate (long[] pattern, int repeat); 676 677 /** Stops the vibrator */ cancelVibrate()678 public void cancelVibrate (); 679 680 /** The azimuth is the angle of the device's orientation around the z-axis. The positive z-axis points towards the earths 681 * center. 682 * 683 * @see <a 684 * href="http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])">http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])</a> 685 * @return the azimuth in degrees */ getAzimuth()686 public float getAzimuth (); 687 688 /** The pitch is the angle of the device's orientation around the x-axis. The positive x-axis roughly points to the west and is 689 * orthogonal to the z- and y-axis. 690 * @see <a 691 * href="http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])">http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])</a> 692 * @return the pitch in degrees */ getPitch()693 public float getPitch (); 694 695 /** The roll is the angle of the device's orientation around the y-axis. The positive y-axis points to the magnetic north pole 696 * of the earth. 697 * @see <a 698 * href="http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])">http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])</a> 699 * @return the roll in degrees */ getRoll()700 public float getRoll (); 701 702 /** Returns the rotation matrix describing the devices rotation as per <a href= 703 * "http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])" 704 * >SensorManager#getRotationMatrix(float[], float[], float[], float[])</a>. Does not manipulate the matrix if the platform 705 * does not have an accelerometer. 706 * @param matrix */ getRotationMatrix(float[] matrix)707 public void getRotationMatrix (float[] matrix); 708 709 /** @return the time of the event currently reported to the {@link InputProcessor}. */ getCurrentEventTime()710 public long getCurrentEventTime (); 711 712 /** Sets whether the BACK button on Android should be caught. This will prevent the app from being paused. Will have no effect 713 * on the desktop. 714 * 715 * @param catchBack whether to catch the back button */ setCatchBackKey(boolean catchBack)716 public void setCatchBackKey (boolean catchBack); 717 718 /** @return whether the back button is currently being caught */ isCatchBackKey()719 public boolean isCatchBackKey (); 720 721 /** Sets whether the MENU button on Android should be caught. This will prevent the onscreen keyboard to show up. Will have no 722 * effect on the desktop. 723 * 724 * @param catchMenu whether to catch the menu button */ setCatchMenuKey(boolean catchMenu)725 public void setCatchMenuKey (boolean catchMenu); 726 727 /** @return whether the menu button is currently being caught */ isCatchMenuKey()728 public boolean isCatchMenuKey (); 729 730 /** Sets the {@link InputProcessor} that will receive all touch and key input events. It will be called before the 731 * {@link ApplicationListener#render()} method each frame. 732 * 733 * @param processor the InputProcessor */ setInputProcessor(InputProcessor processor)734 public void setInputProcessor (InputProcessor processor); 735 736 /** @return the currently set {@link InputProcessor} or null. */ getInputProcessor()737 public InputProcessor getInputProcessor (); 738 739 /** Queries whether a {@link Peripheral} is currently available. In case of Android and the {@link Peripheral#HardwareKeyboard} 740 * this returns the whether the keyboard is currently slid out or not. 741 * 742 * @param peripheral the {@link Peripheral} 743 * @return whether the peripheral is available or not. */ isPeripheralAvailable(Peripheral peripheral)744 public boolean isPeripheralAvailable (Peripheral peripheral); 745 746 /** @return the rotation of the device with respect to its native orientation. */ getRotation()747 public int getRotation (); 748 749 /** @return the native orientation of the device. */ getNativeOrientation()750 public Orientation getNativeOrientation (); 751 752 public enum Orientation { 753 Landscape, Portrait 754 } 755 756 /** Only viable on the desktop. Will confine the mouse cursor location to the window and hide the mouse cursor. X and y 757 * coordinates are still reported as if the mouse was not catched. 758 * @param catched whether to catch or not to catch the mouse cursor */ setCursorCatched(boolean catched)759 public void setCursorCatched (boolean catched); 760 761 /** @return whether the mouse cursor is catched. */ isCursorCatched()762 public boolean isCursorCatched (); 763 764 /** Only viable on the desktop. Will set the mouse cursor location to the given window coordinates (origin top-left corner). 765 * @param x the x-position 766 * @param y the y-position */ setCursorPosition(int x, int y)767 public void setCursorPosition (int x, int y); 768 } 769