• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.tests;
18 
19 import com.badlogic.gdx.Gdx;
20 import com.badlogic.gdx.Input.Buttons;
21 import com.badlogic.gdx.Input.Keys;
22 import com.badlogic.gdx.InputProcessor;
23 import com.badlogic.gdx.tests.utils.GdxTest;
24 
25 public class InputTest extends GdxTest implements InputProcessor {
26 
27 	@Override
create()28 	public void create () {
29 // Gdx.input = new RemoteInput();
30 		Gdx.input.setInputProcessor(this);
31 // Gdx.input.setCursorCatched(true);
32 	}
33 
34 	@Override
render()35 	public void render () {
36 		if (Gdx.input.justTouched()) {
37 			Gdx.app.log("Input Test", "just touched, button: " + (Gdx.input.isButtonPressed(Buttons.LEFT) ? "left " : "")
38 				+ (Gdx.input.isButtonPressed(Buttons.MIDDLE) ? "middle " : "")
39 				+ (Gdx.input.isButtonPressed(Buttons.RIGHT) ? "right" : "")
40 				+ (Gdx.input.isButtonPressed(Buttons.BACK) ? "back" : "")
41 				+ (Gdx.input.isButtonPressed(Buttons.FORWARD) ? "forward" : ""));
42 		}
43 
44 		for (int i = 0; i < 10; i++) {
45 			if (Gdx.input.getDeltaX(i) != 0 || Gdx.input.getDeltaY(i) != 0) {
46 				Gdx.app.log("Input Test", "delta[" + i + "]: " + Gdx.input.getDeltaX(i) + ", " + Gdx.input.getDeltaY(i));
47 			}
48 		}
49 // Gdx.input.setCursorPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
50 // if(Gdx.input.isTouched()) {
51 // Gdx.app.log("Input Test", "is touched");
52 // }
53 	}
54 
55 	@Override
keyDown(int keycode)56 	public boolean keyDown (int keycode) {
57 		Gdx.app.log("Input Test", "key down: " + keycode);
58 		if (keycode == Keys.G) Gdx.input.setCursorCatched(!Gdx.input.isCursorCatched());
59 		return false;
60 	}
61 
62 	@Override
keyTyped(char character)63 	public boolean keyTyped (char character) {
64 		Gdx.app.log("Input Test", "key typed: '" + character + "'");
65 		return false;
66 	}
67 
68 	@Override
keyUp(int keycode)69 	public boolean keyUp (int keycode) {
70 		Gdx.app.log("Input Test", "key up: " + keycode);
71 		return false;
72 	}
73 
74 	@Override
touchDown(int x, int y, int pointer, int button)75 	public boolean touchDown (int x, int y, int pointer, int button) {
76 		Gdx.app.log("Input Test", "touch down: " + x + ", " + y + ", button: " + getButtonString(button));
77 		return false;
78 	}
79 
80 	@Override
touchDragged(int x, int y, int pointer)81 	public boolean touchDragged (int x, int y, int pointer) {
82 		Gdx.app.log("Input Test", "touch dragged: " + x + ", " + y + ", pointer: " + pointer);
83 		return false;
84 	}
85 
86 	@Override
touchUp(int x, int y, int pointer, int button)87 	public boolean touchUp (int x, int y, int pointer, int button) {
88 		Gdx.app.log("Input Test", "touch up: " + x + ", " + y + ", button: " + getButtonString(button));
89 		return false;
90 	}
91 
92 	@Override
mouseMoved(int x, int y)93 	public boolean mouseMoved (int x, int y) {
94 		Gdx.app.log("Input Test", "touch moved: " + x + ", " + y);
95 		return false;
96 	}
97 
98 	@Override
scrolled(int amount)99 	public boolean scrolled (int amount) {
100 		Gdx.app.log("Input Test", "scrolled: " + amount);
101 		return false;
102 	}
103 
getButtonString(int button)104 	private String getButtonString (int button) {
105 		if (button == Buttons.LEFT) return "left";
106 		if (button == Buttons.RIGHT) return "right";
107 		if (button == Buttons.MIDDLE) return "middle";
108 		if (button == Buttons.BACK) return "back";
109 		if (button == Buttons.FORWARD) return "forward";
110 		return "unknown";
111 	}
112 }
113