From 435d838e63549a7b29e4a1843a0c620a18b91bb5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Fri, 9 Jan 2015 09:52:33 -0500 Subject: [PATCH] lib/android: add the gamepad module MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/android/gamepad.nit | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 lib/android/gamepad.nit diff --git a/lib/android/gamepad.nit b/lib/android/gamepad.nit new file mode 100644 index 0000000..be0ded0 --- /dev/null +++ b/lib/android/gamepad.nit @@ -0,0 +1,78 @@ +# This file is part of NIT (http://www.nitlanguage.org). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Support for gamepad events (over Bluetooth or USB) +module gamepad + +import input_events + +redef class AndroidKeyEvent + + # Was `self` raised by the A button? + fun is_a: Bool do return key_code == 96 + + # Was `self` raised by the B button? + fun is_b: Bool do return key_code == 97 + + # Was `self` raised by the X button? + fun is_x: Bool do return key_code == 99 + + # Was `self` raised by the Y button? + fun is_y: Bool do return key_code == 100 + + # Was `self` raised by the directional pad? + fun is_dpad: Bool + do + return is_dpad_up or is_dpad_down or is_dpad_left or is_dpad_right + end + + # Was `self` raised by the up key on the directional pad? + fun is_dpad_up: Bool do return key_code == 19 + + # Was `self` raised by the down key on the directional pad? + fun is_dpad_down: Bool do return key_code == 20 + + # Was `self` raised by the left key on the directional pad? + fun is_dpad_left: Bool do return key_code == 21 + + # Was `self` raised by the right key on the directional pad? + fun is_dpad_right: Bool do return key_code == 22 + + # Was `self` raised by the start button? + fun is_start: Bool do return key_code == 108 + + # Was `self` raised by the select button? + fun is_select: Bool do return key_code == 109 + + # Was `self` raised by the right bumper button? + fun is_bumper_right: Bool do return key_code == 103 + + # Was `self` raised by the right trigger? + fun is_trigger_right: Bool do return key_code == 105 + + # Was `self` raised by the left bumper? + fun is_bumper_left: Bool do return key_code == 102 + + # Was `self` raised by the left trigger? + fun is_trigger_left: Bool do return key_code == 101 + + # Was `self` raised by the media button 'previous'? + fun is_media_previous: Bool do return key_code == 87 + + # Was `self` raised by the media button 'pause'? + fun is_media_pause: Bool do return key_code == 85 + + # Was `self` raised by the media button 'next'? + fun is_media_next: Bool do return key_code == 88 +end -- 1.7.9.5