Toggle switch on keyboard to SendKeys?

Announcements, general discussion
Post Reply
axebeard
Posts: 3
Joined: 01 May 2019, 07:33

Toggle switch on keyboard to SendKeys?

Post by axebeard » 01 May 2019, 07:42

I found HIDMacros while trying to put together some flight sim panels. I have a toggle switch replacing keyboard keys and am trying to figure out how to get that to become a single keypress rather than jamming down the keyboard key like it normally does.

The keyboard in this case is called Keyb1, and I'm wondering if this script SHOULD be working, because it doesn't appear to be:

if HIDMacros.IsButtonPressed("Keyb1", 50) then
HIDMacros.SendKeys "f"
else
HIDMacros.SendKeys "a"
end if

In Notepad, it just sends a constant stream of 2's rather than "f" or "a".

axebeard
Posts: 3
Joined: 01 May 2019, 07:33

Re: Toggle switch on keyboard to SendKeys?

Post by axebeard » 01 May 2019, 22:24

This sort of works, but it doesn't translate to DCS for some reason:

local a0,a1,b0,b1,c0,c1,d0,d1
a0, a1, b0 ,b1, c0, c1, d0, d1 = 0,0,0,0,0,0,0,0

-- assign logical name to macro keyboard
lmc_assign_keyboard('MACROS');

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

--on button down (TOGGLE)
if (button == 50 and direction ==1 and a0 ==0) then
lmc_send_keys('+{z}')
a0 = 1
a1 = 0
--on button released (TOGGLE)
elseif
(button == 50 and direction ==0 and a1 ==0) then
lmc_send_keys('+{x}')
a1 = 1
a0 = 0

elseif (button == string.byte('N')) then lmc_spawn("notepad", "C:\\test.txt")
elseif (button == string.byte('H')) then lmc_send_keys('Hello world')
else print('Not yet assigned: ' .. button)
end
end)

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

Re: Toggle switch on keyboard to SendKeys?

Post by admin » 02 May 2019, 08:04

The key repeat comes from keyboard driver and you can't stop it (unless changing in windows globally).
What you can do is intentionally ignore following key downs - as you do in luamacros script.
If they keys don't arrive to DCS it might be by its architecture and way it reads keyboard - see https://github.com/me2d13/luamacros/wik ... -keyboards for details.
In other words: if the script works in "regular" program (like notepad) and not in DCS there's not much you can do
Petr Medek
LUAmacros author

axebeard
Posts: 3
Joined: 01 May 2019, 07:33

Re: Toggle switch on keyboard to SendKeys?

Post by axebeard » 02 May 2019, 20:53

Yeah, it seems to just not be reaching DCS, which is unfortunate, because this was the only program I found that was able to turn a hardware toggle switch into a single keypress.

Post Reply