Luamacros and holding key

Announcements, questions
Post Reply
tomrach
Posts: 9
Joined: 07 Mar 2020, 19:26

Luamacros and holding key

Post by tomrach » 30 May 2020, 10:02

Hello. How to write a script so that holding down the key increases the value in x plane?, E.g. if I press and hold the G key, the flight altitude increases until I release the G key. On HidMacros it worked without a problem but in luamacros I have to write special scripts. Thank you for your help.

admin
Site Admin
Posts: 655
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Luamacros and holding key

Post by admin » 01 Jun 2020, 07:53

I didn't try but it should work in luamacros as well, the keyboard driver should send repeated key-down events. Aren't you ignoring down direction? Share your script.
And if you really receive just one key-down event, you should be able achieve this using timers - set some flag on key down and then in timer handler, if the flag is set, modify your alt pre-set.
Petr Medek
LUAmacros author

tomrach
Posts: 9
Joined: 07 Mar 2020, 19:26

Re: Luamacros and holding key

Post by tomrach » 09 Jun 2020, 08:06

It's ok. But some Zibo commands do not work for me when assigned to any key. I thought it was the Zibo version but the commands work on HidMacros. This is my script:
-- assign logical name to macro keyboard
lmc_assign_keyboard('MACROS');
lmc_print_devices()

-- define callback for whole device
lmc_set_handler('MACROS',function(button, direction)
if (direction == 0) then return end
if (button == string.byte('A')) then lmc_xpl_command('laminar/B738/autopilot/vs_press') --V/S
elseif (button == string.byte('D')) then lmc_xpl_command('laminar/B738/autopilot/app_press') --APP
elseif (button == string.byte('S')) then lmc_xpl_command('laminar/B738/autopilot/alt_hld_press') --ALT HLD
elseif (button == string.byte('1')) then lmc_xpl_command('laminar/B738/autopilot/flight_director_fo_toggle') --F/D FO
elseif (button == string.byte('2')) then lmc_xpl_command('laminar/B738/autopilot/flight_director_toggle') --F/D CPT
elseif (button == string.byte('3')) then lmc_xpl_command('laminar/B738/toggle_switch/r_pack_dn') --R PACK DOWN
elseif (button == string.byte('4')) then lmc_xpl_command('laminar/B738/toggle_switch/r_pack_up') --R PACK UP
elseif (button == string.byte('5')) then lmc_xpl_command('laminar/B738/toggle_switch/l_pack_dn') --L PACK DOWN
elseif (button == string.byte('6')) then lmc_xpl_command('laminar/B738/toggle_switch/l_pack_up') --L PACK UP
elseif (button == string.byte('7')) then lmc_xpl_command('laminar/B738/toggle_switch/bleed_air_apu') --APU BLEED
elseif (button == string.byte('8')) then lmc_xpl_command('laminar/B738/toggle_switch/bleed_air_2') --BLEED 2
elseif (button == string.byte('9')) then lmc_xpl_command('laminar/B738/toggle_switch/bleed_air_1') --BLEED 1
elseif (button == string.byte('0')) then lmc_xpl_command('laminar/B738/knob/flt_alt_press_up') --FLT ALT UP
elseif (button == 189) then lmc_xpl_command('laminar/B738/knob/flt_alt_press_dn') --FLT ALT DOWN
elseif (button == 187) then lmc_xpl_command('laminar/B738/knob/land_alt_press_up') --LAND ALT UP
elseif (button == 220) then lmc_xpl_command('laminar/B738/knob/land_alt_press_dn') --LAND ALT DOWN
elseif (button == 8) then lmc_xpl_command('laminar/B738/switch/wheel_light_toggle') --WHEEL WELL LIGHT
elseif (button == 9) then lmc_xpl_command('laminar/B738/autopilot/altitude_up') --ALT UP
elseif (button == 81) then lmc_xpl_command('laminar/B738/autopilot/altitude_dn') --ALT DOWN
elseif (button == 87) then lmc_xpl_command('laminar/B738/autopilot/heading_up') --HDG UP
elseif (button == 69) then lmc_xpl_command('laminar/B738/autopilot/heading_dn') --HDG DOWN
elseif (button == 82) then lmc_xpl_command('sim/autopilot/airspeed_up') --IAS UP
elseif (button == 84) then lmc_xpl_command('sim/autopilot/airspeed_dn') --IAS DOWN
elseif (button == 89) then lmc_xpl_command('laminar/B738/autopilot/course_pilot_up') --COURSE UP
elseif (button == 85) then lmc_xpl_command('laminar/B738/autopilot/course_pilot_dn') --COURSE DOWN
elseif (button == 73) then lmc_xpl_command('laminar/B738/EFIS_control/capt/push_button/std_press') --QNH STD
elseif (button == 79) then lmc_xpl_command('laminar/B738/pilot/barometer_up') --QNH UP
elseif (button == 80) then lmc_xpl_command('laminar/B738/pilot/barometer_down') --QNH DOWN
elseif (button == 219) then lmc_xpl_command('laminar/B738/pfd/dh_pilot_up') --BARO MINIMA UP
elseif (button == 221) then lmc_xpl_command('laminar/B738/pfd/dh_pilot_dn') --BARO MINIMA DOWN
elseif (button == 70) then lmc_xpl_command('laminar/B738/autopilot/vorloc_press') --VOR LOC
elseif (button == 71) then lmc_xpl_command('laminar/B738/autopilot/hdg_sel_press') --HDG SEL
elseif (button == 72) then lmc_xpl_command('laminar/B738/autopilot/lnav_press') --LNAV
elseif (button == 74) then lmc_xpl_command('laminar/B738/autopilot/vnav_press') --VNAV
elseif (button == 75) then lmc_xpl_command('laminar/B738/autopilot/lvl_chg_press') --LVL CHG
elseif (button == 76) then lmc_xpl_command('laminar/B738/autopilot/speed_press') --SPEED MODE
elseif (button == 186) then lmc_xpl_command('sim/autopilot/vertical_speed_up') --V/S UP
elseif (button == 222) then lmc_xpl_command('sim/autopilot/vertical_speed_down') --V/S DOWN
elseif (button == 190) then lmc_xpl_command('laminar/B738/engine/mixture2_toggle') --CUT OFF 2
elseif (button == 191) then lmc_xpl_command('laminar/B738/engine/mixture1_toggle') --CUT OFF 1
elseif (button == 16) then lmc_xpl_command('laminar/B738/knob/autobrake_dn') --AUTOBRAKE DOWN
elseif (button == 17) then lmc_xpl_command('laminar/B738/knob/autobrake_up') --AUTOBRAKE UP
elseif (button == 27) then lmc_xpl_command('laminar/B738/toggle_switch/window_heat_r_side') --WIND HEAT RIGHT 1
elseif (button == 112) then lmc_xpl_command('laminar/B738/toggle_switch/window_heat_r_fwd') --WIND HEAT RIGHT 2
elseif (button == 113) then lmc_xpl_command('laminar/B738/toggle_switch/window_heat_l_fwd') --WIND HEAT LEFT 2
elseif (button == 114) then lmc_xpl_command('laminar/B738/toggle_switch/window_heat_l_side') --WIND HEAT LEFT 1
elseif (button == 115) then lmc_xpl_command('laminar/B738/toggle_switch/fo_probes_pos') --PROBE HEAT RIGHT
elseif (button == 116) then lmc_xpl_command('laminar/B738/toggle_switch/capt_probes_pos') --PROBE HEAT LEFT
elseif (button == 117) then lmc_xpl_command('laminar/B738/toggle_switch/eng2_heat') --ENG ANTI ICE 2
elseif (button == 118) then lmc_xpl_command('laminar/B738/toggle_switch/eng1_heat') --ENG ANTI ICE 1
elseif (button == 119) then lmc_xpl_command('laminar/B738/toggle_switch/wing_heat') --WING ANTI ICE
elseif (button == 120) then lmc_xpl_command('laminar/B738/knob/eng2_start_right') --ENGINE 2 START RIGHT
elseif (button == 121) then lmc_xpl_command('laminar/B738/knob/eng2_start_left') --ENGINE 2 START LEFT
elseif (button == 122) then lmc_xpl_command('laminar/B738/knob/eng1_start_right') --ENGINE 1 START RIGHT
elseif (button == 123) then lmc_xpl_command('laminar/B738/knob/eng1_start_left') --ENGINE 1 START LEFT
elseif (button == 145) then lmc_xpl_command('laminar/B738/switch/wing_light_toggle') --WING LIGHT
elseif (button == 19) then lmc_xpl_command('sim/lights/beacon_lights_toggle') --ANTICOLLISION LIGHT
elseif (button == 45) then lmc_xpl_command('laminar/B738/toggle_switch/position_light_down') --POSITION LIGHT DOWN
elseif (button == 36) then lmc_xpl_command('laminar/B738/toggle_switch/position_light_up') --POSITION LIGHT UP
elseif (button == 33) then lmc_xpl_command('laminar/B738/switch/land_lights_right') --LANDING LIGHT RIGHT OFF
elseif (button == 46) then lmc_xpl_command('laminar/B738/switch/land_lights_left') --LANDING LIGHT LEFT OFF
elseif (button == 35) then lmc_xpl_command('laminar/B738/switch/land_lights_ret_right_up') --RETR LIGHT RIGHT UP
elseif (button == 34) then lmc_xpl_command('laminar/B738/switch/land_lights_ret_left_up') --RETR LIGHT LEFT UP
elseif (button == 38) then lmc_xpl_command('laminar/B738/spring_switch/landing_lights_all') --ALL LANDING LIGHTS ON
elseif (button == 37) then lmc_xpl_command('laminar/B738/toggle_switch/taxi_light_brigh_toggle') --TAXI LIGHTS
elseif (button == 40) then lmc_xpl_command('laminar/B738/switch/rwy_light_right_toggle') --RWY LIGHT RIGHT
elseif (button == 39) then lmc_xpl_command('laminar/B738/switch/rwy_light_left_toggle') --RWY LIGHT LEFT
elseif (button == 111) then lmc_xpl_command('laminar/B738/spring_toggle_switch/APU_start_pos_up') --APU OFF
elseif (button == 106) then lmc_xpl_command('laminar/B738/spring_toggle_switch/APU_start_pos_dn') --APU ON
elseif (button == 109) then lmc_xpl_command('laminar/B738/spring_toggle_switch/APU_start_pos_dn') --APU START
elseif (button == 103) then lmc_xpl_command('laminar/B738/toggle_switch/gen2_dn') --GEN 2 DOWN
elseif (button == 104) then lmc_xpl_command('laminar/B738/toggle_switch/apu_gen2_dn') --APU GEN 2 DOWN
elseif (button == 105) then lmc_xpl_command('laminar/B738/toggle_switch/apu_gen1_dn') --APU GEN 1 DOWN
elseif (button == 107) then lmc_xpl_command('laminar/B738/toggle_switch/gen1_dn') --GEN 1 DOWN
elseif (button == 100) then lmc_xpl_command('laminar/B738/toggle_switch/electric_hydro_pumps2') --HYD PUMP 2
elseif (button == 101) then lmc_xpl_command('laminar/B738/toggle_switch/gpu_dn') --GPU ON
elseif (button == 102) then lmc_xpl_command('laminar/B738/toggle_switch/electric_hydro_pumps1') --HYD PUMP 1
elseif (button == 97) then lmc_xpl_command('laminar/B738/toggle_switch/fuel_pump_rgt1') --FUEL PUMP RIGHT1
elseif (button == 98) then lmc_xpl_command('laminar/B738/toggle_switch/fuel_pump_rgt2') --FUEL PUMP RIGHT2
elseif (button == 99) then lmc_xpl_command('laminar/B738/toggle_switch/fuel_pump_lft2') --FUEL PUMP LEFT 2
elseif (button == 13) then lmc_xpl_command('laminar/B738/toggle_switch/fuel_pump_lft1') --FUEL PUMP LEFT 1
elseif (button == 96) then lmc_xpl_command('laminar/B738/toggle_switch/fuel_pump_ctr2') --FUEL PUMP CTR 2
elseif (button == 110) then lmc_xpl_command('laminar/B738/toggle_switch/fuel_pump_ctr1') --FUEL PUMP CTR 1
elseif (button == 192) then lmc_xpl_command('laminar/B738/autopilot/autothrottle_arm_toggle') --A/T ARM
else print('To use this key add elseif with number ' .. button)
-- Hide window to tray to keep taskbar tidy
lmc.minimizeToTray = true
--lmc_minimize()

end
end)

Command "elseif (button == 73) then lmc_xpl_command('laminar/B738/EFIS_control/capt/push_button/std_press')" and "elseif (button == 84) then lmc_xpl_command('sim/autopilot/airspeed_dn')" do not work.

P.S.
I really want luamacros to work fully because I'm going to change Windows 7 to Windows 10 and HidMacrosXPL.xpl plugin does not work on win10 (x Plane crashing when loading).

tomrach
Posts: 9
Joined: 07 Mar 2020, 19:26

Re: Luamacros and holding key

Post by tomrach » 12 Jun 2020, 07:41

is there any solution for this problem?

admin
Site Admin
Posts: 655
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Luamacros and holding key

Post by admin » 15 Jun 2020, 19:16

Do some debugging first.
Is holding a key the problem or not working commands?
For me holding a key works fine. This code

Code: Select all

lmc_device_set_name('KBD1', 'D80462F') -- upper
log_handler = function(button, direction, ts, flags)
  print('Callback for device: button ' .. button .. ', direction '..direction..', ts '..ts..', flags '..flags)
end
lmc_set_handler('KBD1', log_handler)
Produces this log when holding a key

Code: Select all

Callback for device: button 84, direction 1, ts 3441375, flags 0
Callback for device: button 84, direction 1, ts 3441406, flags 0
Callback for device: button 84, direction 1, ts 3441437, flags 0
Callback for device: button 84, direction 1, ts 3441468, flags 0
Callback for device: button 84, direction 1, ts 3441500, flags 0
Callback for device: button 84, direction 1, ts 3441531, flags 0
Callback for device: button 84, direction 1, ts 3441562, flags 0
Callback for device: button 84, direction 0, ts 3441593, flags 1
So make your script as simple as possible and isolate what doesn't work.
Petr Medek
LUAmacros author

tomrach
Posts: 9
Joined: 07 Mar 2020, 19:26

Re: Luamacros and holding key

Post by tomrach » 16 Jun 2020, 09:05

I tested luamacros on Windows 10. After loading any script, a window pops up with this error:

System Error, (OS Code 3):
The system cannot find the path specified.
.
Press OK to ignore and risk data corruption.
Press Cancel to kill the program.

I don't know what the dot between the second and third lines means. I will add that I started the program as an administrator.
What should I do?

admin
Site Admin
Posts: 655
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Luamacros and holding key

Post by admin » 17 Jun 2020, 07:26

Try to put luamacros to some simple path, like C:\luamacors and open the file from that directory. Make sure you have no special characters in the path of the file you're trying to open.
Regarding dots - I don't see any dots between lines. Learn lua, you can't use luamacros without knowing lua.
Petr Medek
LUAmacros author

tomrach
Posts: 9
Joined: 07 Mar 2020, 19:26

Re: Luamacros and holding key

Post by tomrach » 17 Jun 2020, 18:07

I mean the dot under the sentence "The system cannot find the path specified" and above the sentence "Press OK to ignore and risk data corruption" in error in the previous post.

Post Reply