One Button Push - Three Unique Macro Outputs
Posted: 19 Oct 2019, 17:46
Hey Petr,
I just received a two button keyboard needed for my idea. I'm going to use this keyboard to cycle through three macros when one of the two keys (key 88) is clicked repeatedly. Petr was a hero and created the following script for me.
I just received a two button keyboard needed for my idea. I'm going to use this keyboard to cycle through three macros when one of the two keys (key 88) is clicked repeatedly. Petr was a hero and created the following script for me.
- I noticed that lmc_assign_keyboard is different than what most use which is lmc_device_set_name. Is my syntax correct for lmc_assign_keyboard?
- How do you specify the key number to this script? I'd like to execute the macros when key 88 is pressed. Would this be correct mc_send_input(string.byte(88), 0, 0) ?
- In regards to what is printed when the key is pressed where is that defined? I'm looking for something like "+^%{m}"
Code: Select all
-- this example sends 3 different key combinations on 'A' key press
-- choose keyboard for macros, assign logical name
lmc_assign_keyboard('MACROS','39505B2E');
-- on every trigger following keys with alt + shift are send - looped with every press
keysToSend = { 'A', 'B', 'C'}
currentIndex = 1
-- send any key (letter) as keystroke. Any key defined by the keyboard is used as THE key.
function press(key)
lmc_send_input(string.byte(key), 0, 0) -- press
lmc_send_input(string.byte(key), 0, 2) -- release
end
-- wraps function call with shift press
function withShift(callback)
lmc_send_input(16, 0, 0) -- press
callback()
lmc_send_input(16, 0, 2) -- release
end
-- wraps function call with alt press
function withAlt(callback)
lmc_send_input(18, 0, 0) -- press
callback()
lmc_send_input(18, 0, 2) -- release
end
-- define callback for 'A' key
lmc_set_handler('MACROS',65,0,function(button, direction)
withAlt(function() withShift(function() press(keysToSend[currentIndex]) end) end)
currentIndex = (currentIndex == #keysToSend and 1 or currentIndex + 1)
end)