me2d13 / luamacros

665 stars 87 forks source link

Pressing other button or same on release #38

Closed markozivkovich closed 5 years ago

markozivkovich commented 5 years ago

Hello Petr, I need help with LuaMacros. Is there any chance when I execute my code:

lmc_device_set_name('lul','1549AFE2') lmc_print_devices()

lmc_set_handler('lul', function(button,direction) if ( direction == 1) then lmc_send_input(17, 0, 0) elseif (direction == 0) then lmc_send_input(17, 0, 2) lmc_send_input(17, 0, 0) lmc_send_input(17, 0, 2) end end )

To work only when i press left ctrl, and all other keys to work properly, I have only one keyboard.

chesteripz commented 5 years ago

If you are using one keyboard only, maybe AutoHotKey is easier to work with?

markozivkovich commented 5 years ago

No sir, ahk even if it's running in background many games do not allow it, can't risk the ban. My upper written code is working, but i just don't know how to execute it with single button

me2d13 commented 5 years ago

Yes, you can define handler (callback function) only for one key (left ctrl) and other's won't be affected. You need to add additional parameters to lmc_set_handler. See https://github.com/me2d13/luamacros/wiki/Triggers#specific-key

markozivkovich commented 5 years ago

I have read it, but when example -

In first case: I define handler

lmc_set_handler('lul',76,1,function(button,direction) if ( direction == 1) then lmc_send_input(65, 0, 0) lmc_send_input(65, 0, 2) elseif (direction == 0) then lmc_send_input(80, 0, 0) lmc_send_input(80, 0, 2) end end )

like this only executes the first part or " if ( direction == 1) then" part of function

In first case: I define handler

lmc_set_handler('lul',76,0,function(button,direction) if ( direction == 1) then lmc_send_input(65, 0, 0) lmc_send_input(65, 0, 2) elseif (direction == 0) then lmc_send_input(80, 0, 0) lmc_send_input(80, 0, 2) end end )

And like this only executes the second part or " elseif (direction == 0) then" part of function

How to do it both?

me2d13 commented 5 years ago

Set 2 handlers and you don't need the if for direction in callback function. You can call lmc_set_handler any times you want with different parameters. So something like:

lmc_set_handler('lul',76,1,function(button) lmc_send_input(65, 0, 0) lmc_send_input(65, 0, 2) end )

lmc_set_handler('lul',76,0,function(button) lmc_send_input(80, 0, 0) lmc_send_input(80, 0, 2) end )

markozivkovich commented 5 years ago

Thank you very much now that is it.