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')
function keyboardHandler(eventType, character, keycode, modifiers)
if eventType==eEvtKeyUp then
print('key up: ' .. keycode)
-- test for '0' with character parameter
if character == '0' then print('0 released') end
-- another option to test '0' key
if keycode == 48 then print('0 released') end
elseif eventType==eEvtKeyDown then
print('key down: ' .. keycode)
elseif eventType==eEvtKeyTextInput then
-- this will also show more 'complex' unicode characters when multiple keys are used to generate a single character (e.g. Chinese characters)
print('input: ' .. character)
end
if keycode == eKeyEscape then
-- event will not be handled by engine. this means that also cutscenes can't be skipped with Escape key
return true
end
return false -- key event will also be handled by engine
end
registerEventHandler("keyEvent", "keyboardHandler")
if keycode == 80 then -- left
charmove_x = 0
if keycode == 80 OR XYZ then -- left
charmove_x = 0
function keyboardHandler(eventType, character, keycode, modifiers)
if eventType==eEvtKeyUp then
print('key up: ' .. keycode)
keycode = keycode % 1073741824
if keycode == 80 or 97 then -- left
charmove_x = 0
elseif keycode == 79 or 100 then -- right
charmove_x = 0
elseif keycode == 81 or 115 then -- down
charmove_y = 0
elseif keycode == 82 or 119 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 or 97 then -- left
charmove_x = -100
elseif keycode == 79 or 100 then -- right
charmove_x = 100
elseif keycode == 81 or 115 then -- down
charmove_y = 100
elseif keycode == 82 or 119 then -- up
charmove_y = -100
end