Alt down does seem to still pass through

Report application bugs here
Post Reply
Posts: 2
Joined: 22 Oct 2018, 13:58

Alt down does seem to still pass through

Post by pajn » 22 Oct 2018, 14:04

I'm trying to change place of the ALT and WIN key only on my laptop but not for external keyboards.
I have created this program

Code: Select all

-- assign logical name to macro keyboard

-- direction 1 = down
-- direction 0 = up
-- button 18 = alt
-- button 91 = win
-- lmc_send_input(65, 0, 0) -- press A
-- lmc_send_input(65, 0, 2) -- release A

-- define callback for whole device
lmc_set_handler('MACROS',function(button, direction)
  print('button: ' .. button .. ' direction: ' .. direction)

  if (button == 18) then -- if ALT
    if (direction == 1) then lmc_send_input(91, 0, 0) -- press WIN
    elseif (direction == 0) then lmc_send_input(91, 0, 2) -- release WIN
  elseif (button == 91) then -- if WIN
    if (direction == 1) then lmc_send_input(18, 0, 0) -- press ALT
    elseif (direction == 0) then lmc_send_input(18, 0, 2) -- release ALT
    if (direction == 1) then lmc_send_input(button, 0, 0) -- pass through press
    elseif (direction == 0) then lmc_send_input(button, 0, 2) -- pass through release

The win key seem to work nicely as an alt key, but the alt key works strangely. I suspect that it still passes though alt down (as well as what I send), but not alt up.

Is ALT a special key or is my lua program crap?
I have tried running as admin with the same result.

Site Admin
Posts: 538
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic

Re: Alt down does seem to still pass through

Post by admin » 23 Oct 2018, 08:19

Your code seems to be ok (btw lmc_set_handler can be assigned only to one key, not to whole device, with additional parameter).
So I would say Alt is somehow special - what exactly doesn't work? The triggering part or the send_input part? You can add some debug output to see if triggers are ok.
Petr Medek
LUAmacros author

Posts: 2
Joined: 22 Oct 2018, 13:58

Re: Alt down does seem to still pass through

Post by pajn » 23 Oct 2018, 09:40

Thanks for the tip about only assigning it to specific keys.

Both triggering and send_input seems to work, it's just that the ALT key is sent as well.
For example if I instead of WIN key down send TAB key down on ALT, pressing and releasing ALT once behaves exactly like pressing and holding down ALT + pressing and releasing TAB once.

ALT down => ALT down + TAB down
ALT up => TAB up

I assume the same thing happen with the script as written (sending WIN key instead of TAB key). For example with the script is written, pressing and releasing ALT then lets me tab through open windows with only the TAB key. As ALT up does not seems to be passed through though I have to use the WIN key to actually switch window.

Post Reply