| 1 |
# systemtap input tapset |
| 2 |
# Copyright (C) 2008,2011 Masami Hiramatsu <[email protected]> |
| 3 |
# |
| 4 |
# This file is free software and is distributed under the terms of the GNU |
| 5 |
# General Public License (GPL); either version 2, or (at your option) any |
| 6 |
# later version. |
| 7 |
|
| 8 |
|
| 9 |
probe game.input = kernel.function("input_event").call { |
| 10 |
type = $type |
| 11 |
code = $code |
| 12 |
value = $value |
| 13 |
} |
| 14 |
|
| 15 |
#TODO: convert keycode to char. |
| 16 |
|
| 17 |
# elemental gamepad keys ;-P |
| 18 |
global GM_KBD_UP =103 |
| 19 |
global GM_KBD_DOWN =108 |
| 20 |
global GM_KBD_RIGHT=106 |
| 21 |
global GM_KBD_LEFT =105 |
| 22 |
global GM_KBD_Z =44 |
| 23 |
global GM_KBD_X =45 |
| 24 |
global GM_KBD_C =46 |
| 25 |
global GM_KBD_ESC =1 |
| 26 |
global GM_KBD_SPACE=57 |
| 27 |
|
| 28 |
|
| 29 |
probe game.kbd = game.input { |
| 30 |
if (type != 1 || code >= 256) next; |
| 31 |
down = value |
| 32 |
} |
| 33 |
|
| 34 |
probe game.kbd.down = game.kbd { |
| 35 |
if (!down) next |
| 36 |
} |
| 37 |
|
| 38 |
probe game.kbd.up = game.kbd { |
| 39 |
if (down) next |
| 40 |
} |
| 41 |
|
| 42 |
# mouse |
| 43 |
|
| 44 |
probe game.mouse = game.input { |
| 45 |
if (!(type == 2 || |
| 46 |
(type == 1 && (code & 0xfe0) != 0x100) ) ) next #EV_KEY |
| 47 |
} |
| 48 |
|
| 49 |
probe game.mouse.rel = game.input { |
| 50 |
if(type != 2) next #EV_REL |
| 51 |
if(code == 0) dx = value |
| 52 |
else if(code == 1) dy = value |
| 53 |
else if(code == 8) dz = value |
| 54 |
} |
| 55 |
|
| 56 |
global GM_mouse_abs |
| 57 |
global GM_mouse_base_x, GM_mouse_base_y |
| 58 |
|
| 59 |
probe game.mouse.abs = game.input { |
| 60 |
dx = dy = dz = 0 |
| 61 |
if (type == 1 && code == 0x145 && value == 0) { |
| 62 |
# Leave a finger -- Reset position |
| 63 |
GM_mouse_base_x = 0 |
| 64 |
GM_mouse_base_y = 0 |
| 65 |
next |
| 66 |
} else if (type != 3) next #EV_ABS |
| 67 |
|
| 68 |
if (code == 0) { |
| 69 |
x = value |
| 70 |
if (GM_mouse_base_x != 0) |
| 71 |
dx = x - GM_mouse_base_x |
| 72 |
GM_mouse_base_x = x |
| 73 |
GM_mouse_abs[0] = value |
| 74 |
} else if (code == 1) { |
| 75 |
y = value |
| 76 |
if (GM_mouse_base_y != 0) |
| 77 |
dy = y - GM_mouse_base_y |
| 78 |
GM_mouse_base_y = y |
| 79 |
GM_mouse_abs[1] = value |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
global GM_mouse_btn |
| 84 |
|
| 85 |
probe game.mouse.btn = game.input { |
| 86 |
if (type != 1 || (code & 0xfe0) != 0x100) next #EV_KEY |
| 87 |
button = code & 0xf |
| 88 |
down = value |
| 89 |
if (GM_mouse_btn[button] == down) next |
| 90 |
GM_mouse_btn[button] = down |
| 91 |
} |
| 92 |
|
| 93 |
global GM_mouse_pos |
| 94 |
|
| 95 |
probe game.mouse.rel, game.mouse.abs { |
| 96 |
GM_mouse_pos[0] += dx |
| 97 |
GM_mouse_pos[1] += dy |
| 98 |
GM_mouse_pos[2] += dz |
| 99 |
} |
| 100 |
|
| 101 |
function game_mouse_reset(x:long, y:long, z:long) { |
| 102 |
GM_mouse_pos[0] = x |
| 103 |
GM_mouse_pos[1] = y |
| 104 |
GM_mouse_pos[2] = z |
| 105 |
} |
| 106 |
|
| 107 |
function game_mouse_x:long() { |
| 108 |
return GM_mouse_pos[0] |
| 109 |
} |
| 110 |
|
| 111 |
function game_mouse_y:long() { |
| 112 |
return GM_mouse_pos[1] |
| 113 |
} |
| 114 |
|
| 115 |
function game_mouse_z:long() { |
| 116 |
return GM_mouse_pos[2] |
| 117 |
} |
| 118 |
|