Press one key to start loop, loop until you press another

Announcements, questions
Post Reply
soudescolado
Posts: 2
Joined: 15 Jan 2017, 10:21

Press one key to start loop, loop until you press another

Post by soudescolado » 15 Jan 2017, 10:27

Hello

I'm stuck.

I tried doing some code, but cannot see how to make it work.

What I want is what I said in the title: Start a loop when I press a key, stop it when I press another. However it seems that it queues the next key until the loop is over.

This is what I tried:

Code: Select all

lmc_device_set_name('KBD2', 'MYUSBNUMPADHERE')
lmc_print_devices()

lmc_set_handler('KBD2',function(button, direction)
  print('Callback for whole keyboard 2: button ' .. button .. ', direction '..direction)
    if (direction == 0) then
        if (button == 97) then
            for i = 100,1,-1 do
                print('a pressed')
            end
        end
        if (button == 98) then
            i = 1
        end
    end
end)
And also

Code: Select all

lmc_device_set_name('KBD2', 'MYUSBNUMPADHERE')
lmc_print_devices()
i = 0
while (i < 3) do
    lmc_set_handler('KBD2',function(button, direction)
      print('Callback for whole keyboard 2: button ' .. button .. ', direction '..direction)
        if (direction == 0) then
            if (button == 97) then
                i = 1
            end
            if (button == 98) then
                i = 0
            end
            if (button == 99) then
                i = 3
            end
        end
    end)
    if (i == 1) then
        print('LOL')
    end
end
Also, for now I am using print to test. The key I want to send is SHIFT. Not shift+something, just shift. Can that be done?

Thanks!

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

Re: Press one key to start loop, loop until you press anothe

Post by admin » 15 Jan 2017, 13:46

No, it can't be done.
Macros are enevt driven, you pres a key, lua handler is executed, once it finish, anohter macro handler can be started. It doesn't run in parallel, macros are executed one by one.
I though about introducing some timer - periodical event calls, but there was no reason so far.

Also it's currently not possible to send just shift down;.
Petr Medek
HIDmacros author

soudescolado
Posts: 2
Joined: 15 Jan 2017, 10:21

Re: Press one key to start loop, loop until you press anothe

Post by soudescolado » 15 Jan 2017, 19:43

Bummer. Oh well, thanks!

mrsimb
Posts: 13
Joined: 04 Feb 2017, 00:53

Re: Press one key to start loop, loop until you press anothe

Post by mrsimb » 04 Feb 2017, 01:16

Alternatively, you can hold and fix any unused physical key so it will send press events continuously and trigger key handler. But beware some keys might not be recognized together cause of keyboard architecture. If so - try different key combinations.
edit: No, it would not work. It stops after any key pressed.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests