You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.4 KiB
60 lines
2.4 KiB
-- Multibow internal "module" implementing convenience functions for sending
|
|
-- key presses to the USB host to which the Keybow device is connected to.
|
|
|
|
--[[
|
|
Copyright 2019 Harald Albrecht
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
]]--
|
|
|
|
-- luacheck: globals mb
|
|
|
|
-- Default delay between rapidly (repeated) key presses, can be overridden.
|
|
mb.KEY_DELAY_MS = mb.KEY_DELAY_MS or 100
|
|
|
|
-- Delay between key presses
|
|
function mb.delay()
|
|
keybow.sleep(mb.KEY_DELAY_MS)
|
|
end
|
|
|
|
-- Sends a single key tap to the USB host, optionally with modifier keys, such
|
|
-- as SHIFT (keybow.LEFT_SHIFT), CTRL (keybow.LEFT_CTRL), et cetera. The "key"
|
|
-- parameter can be a string or a Keybow key code, such as keybow.HOME, et
|
|
-- cetera.
|
|
function mb.tap(key, ...)
|
|
mb.tap_times(key, 1, ...)
|
|
end
|
|
|
|
-- Taps the same key multiple times, optionally with modifier keys; however,
|
|
-- for optimization, these modifiers are only pressed once before the tap
|
|
-- sequence, and only released once after all taps.
|
|
function mb.tap_times(key, times, ...)
|
|
for modifier_argno = 1, select("#", ...) do
|
|
local modifier = select(modifier_argno, ...)
|
|
if modifier then keybow.set_modifier(modifier, keybow.KEY_DOWN) end
|
|
end
|
|
for _ = 1, times do
|
|
keybow.tap_key(key)
|
|
mb.delay()
|
|
end
|
|
for modifier_argno = 1, select("#", ...) do
|
|
local modifier = select(modifier_argno, ...)
|
|
if modifier then keybow.set_modifier(modifier, keybow.KEY_UP) end
|
|
end
|
|
end
|
|
|