I had a goal to reprogram my second keyboard into a hotkeys keyboard without 3rd party apps.
It was not so easy cause I got errors using lmc_send_keys function. I don't know what is the reason, but seems RU locale is one.
On the board I found some posts about lmc_send_input and this way works fine for me.
Here's an example.
Code: Select all
local pathWithFilename="D:\\LuaMacros\\samples\\";
local kbID = '226465';
lmc.minimizeToTray = true
lmc_minimize()
clear()
lmc_print_devices()
-- assign logical name to macro keyboard
lmc_device_set_name('MACROS', kbID);
local codes = {
["ctrl"] = 17,
["alt"] = 18,
["shift"] = 16,
["enter"] = 13,
["win"] = 91,
["tab"] = 9,
["space"] = 32,
["back"] = 8,
["app"] = 93,
["left"] = 37,
["right"] = 39,
["up"] = 38,
["down"] = 40,
["insert"]= 45,
["delete"]= 46,
["home"] = 36,
["end"] = 35,
["pup"] = 33,
["esc"] = 27,
["plus"] = 187,
["screen"]= 255,
};
-- define callback for whole device
lmc_set_handler('MACROS', function(button, direction)
if (direction == 1) then
return
end -- ignore down
local config = {};
for line in io.lines(pathWithFilename .. "all.txt") do
local data = {};
for part in string.gmatch(line, "[^%s]+") do
data[#data+1] = part;
end;
config[tonumber(data[1])] = data[2];
end;
if type(config[button]) == "string" then
print('Found: ' .. button .. ' = ' .. config[button]);
for s in string.gmatch(config[button], "[^+]+") do
if type(codes[s]) == "number" then
k = codes[s];
else
k = string.byte(s);
end;
lmc_send_input(k, 0, 0);
end;
for s in string.gmatch(config[button], "[^+]+") do
if type(codes[s]) == "number" then
k = codes[s];
else
k = string.byte(s);
end;
lmc_send_input(k, 0, 2);
end;
else
print('Not yet assigned: ' .. button)
end
end);
all.txt example:
Code: Select all
17 ctrl+alt+A Ctrl
13 ctrl+enter Enter
18 ctrl+shift+I Web inspector
When you start the script you will see a devices list. Get your keyboard ID from the list and set kbID.
Restart the script and enjoy

All codes of all unassigned keys will be printed in LuaMacros console while typing.
Hotkeys adding into the txt file works on-the-fly.
You can run the script on system startup using a shortcut like this:
D:\LuaMacros\LuaMacros.exe "D:\LuaMacros\samples\my.lua" -r