local mouse_x = 0
local mouse_y = 0
local charmove_x = 0
local charmove_y = 0
function keyboardHandler(eventType, character, keycode, modifiers)
if eventType==eEvtKeyUp then
print('key up: ' .. keycode)
keycode = keycode % 1073741824
if keycode == 80 then -- left
charmove_x = 0
elseif keycode == 79 then -- right
charmove_x = 0
elseif keycode == 81 then -- down
charmove_y = 0
elseif keycode == 82 then -- up
charmove_y = 0
end
createEvent('eEvtControllerAxisCharacterMove', {x=charmove_x, y=charmove_y},25)
elseif eventType==eEvtKeyDown then
print('key pressed: ' .. keycode)
keycode = keycode % 1073741824
if keycode == 80 then -- left
charmove_x = -100
elseif keycode == 79 then -- right
charmove_x = 100
elseif keycode == 81 then -- down
charmove_y = 100
elseif keycode == 82 then -- up
charmove_y = -100
end
createEvent('eEvtControllerAxisCharacterMove', {x=charmove_x, y=charmove_y},25)
elseif eventType==eEvtControllerKeyUp then
print('controller up: ' .. keycode)
if keycode == 1000001 then --controller key A up
createEvent('eEvtMouseLeftButtonDown')
createEvent('eEvtMouseLeftButtonUp')
-- createEvent('eEvtKeyDown',{x=0,y=0},eKeyEscape,0)
end
elseif eventType==eEvtControllerKeyDown then
print('controller down: ' .. keycode)
if keycode == 1000001 then --controller key A down
end
elseif eventType==eEvtControllerAxis then
if string.match(character, 'RIGHTX') then
mouse_x = keycode
createEvent('eEvtControllerAxisMouseMove', {x=mouse_x, y=mouse_y}, 19, 9)
elseif string.match(character, 'RIGHTY') then
mouse_y = keycode
createEvent('eEvtControllerAxisMouseMove', {x=mouse_x, y=mouse_y}, 19, 9)
elseif string.match(character, 'LEFTX') then
charmove_x = keycode
createEvent('eEvtControllerAxisCharacterMove', {x=charmove_x, y=charmove_y}, 25)
elseif string.match(character, 'LEFTY') then
charmove_y = keycode
createEvent('eEvtControllerAxisCharacterMove', {x=charmove_x, y=charmove_y}, 25)
end
end
return false
end
registerEventHandler('keyEvent', 'keyboardHandler')