How-To: Use Velocifire NK01 (Standalone Numpad) as Arbitrary Macro Pad

How can be this controlled in that simulator? Can HIDmacros be used with this application?
Post Reply
Jafner
Posts: 1
Joined: 20 Apr 2020, 01:32

How-To: Use Velocifire NK01 (Standalone Numpad) as Arbitrary Macro Pad

Post by Jafner » 20 Apr 2020, 02:07

I wanted a cheap Streamdeck-like device to control my myriad VoiceMeeter Banana controls, as well as some OBS controls (Start/Stop Record, Start/Stop Replay Buffer, Capture Replay). For the hardware, I went with the Velocifire NK01, which was $20 on Amazon when I bought it, because it was wireless, had blue switches, and looked nice aesthetically with my other stuff.

The functionality I wanted:
  • Map each key to Alt+F[X] where X is a number between 1 and 22 (for the 22 keys on the pad). I wanted that so that all of the hotkeys were removed from the things I did on my normal keyboard (Ctrl+NumKeys, for example) because I use my numpad on my main keyboard for many things (incl. games) and didn't want to accidentally trigger any macros. Also, I just felt like it was cleaner.
After a day of fiddling, I got all of it working, with two caveats:
  • The calculator key cannot be used. LuaMacros does not detect any button press when the calculator button is pressed. Someone more savvy than I could probably figure out how to circumvent this issue.
  • Due to the nature of the lmc_send_keys function, you cannot hold a key down. Doing so only causes the designated keystroke to be sent multiple times. This could be fixed by using the lmc_send_input function instead, but I don't need that functionality for my use case.
Here's the code, let me know if this helps you, or if you have any feedback. The keys are addressed in the code in the order left-to-right, top-to-bottom on the physical NK01. They are also grouped by row. This code should be easily generalizable for others with a similar use-case who don't mind those caveats.

Code: Select all

lmc_device_set_name('macros','33332034') -- Assign HID ID to friendly name, 'macros'

lmc_set_handler('macros',function(button, direction) -- Listen to the 'macros' device
-- print(button) -- optional, print each button code when pessed
  if (direction == 0) then return end -- Ignore key release. Only the key press will be registered
  if (button == 27) then  -- Esc
    lmc_send_keys('%{F1}', 50) -- Send Alt+F1
    elseif (button == 9) then  -- Tab
    -- The Velocifire's NK01 has an un-rebindable calculator key here --
    lmc_send_keys('%{F3}', 50)
    elseif (button == 187) then -- NumEqual
    lmc_send_keys('%{F2}', 50) -- This is Alt+F2 instead of Alt-F4 because, uh, well, Alt+F4 closes windows. Shoulda seen this coming...

    elseif (button == 144) then -- NumLock
    lmc_send_keys('%{F5}', 50)
    lmc_send_input(144, 0, 0)
    lmc_send_input(144, 0, 2)
    elseif (button == 111) then -- NumDivide
    lmc_send_keys('%{F6}', 50)
    elseif (button == 106) then -- NumMultiply
    lmc_send_keys('%{F7}', 50)
    elseif (button == 8) then -- NumBackspace
    lmc_send_keys('%{F8}', 50)

    elseif (button == 103) then -- Num7
    lmc_send_keys('%{F9}', 50)
    elseif (button == 104) then -- Num8
    lmc_send_keys('%{F10}', 50)
    elseif (button == 105) then -- Num9
    lmc_send_keys('%{F11}', 50)
    elseif (button == 109) then -- NumMinus
    lmc_send_keys('%{F12}', 50)

    elseif (button == 100) then -- Num4
    lmc_send_keys('%{F13}', 50)
    elseif (button == 101) then -- Num5
    lmc_send_keys('%{F14}', 50)
    elseif (button == 102) then -- Num6
    lmc_send_keys('%{F15}', 50)
    elseif (button == 107) then -- NumPlus
    lmc_send_keys('%{F16}', 50)

    elseif (button == 97) then -- Num1
    lmc_send_keys('%{F17}', 50)
    elseif (button == 98) then -- Num2
    lmc_send_keys('%{F18}', 50)
    elseif (button == 99) then -- Num3
    lmc_send_keys('%{F19}', 50)
    elseif (button == 13) then -- NumEnter
    lmc_send_keys('%{F20}', 50)

    elseif (button == 96) then -- Num0
    lmc_send_keys('%{F21}', 50)
    elseif (button == 110) then -- NumDecimal
    lmc_send_keys('%{F22}', 50)

  end
end
) 
Edit; I am so stupid. I have fixed the issue where the '=' key would close the focused window.

Post Reply