midimonster icon indicating copy to clipboard operation
midimonster copied to clipboard

Multi-Key-Press Commands

Open bengreenow opened this issue 2 years ago • 1 comments

Hey Guys, Absolutely adore this software, such a handy (and amazingly open source!) bit of kit for the power users!

I'm on Windows, and would like my MIDI command to trigger a series of sequetntial key presses, is this possible? I'm familiar with Lua and it feels like that would be the answer but I can't say I'm comfortable enough with it to figure this one out.

Any help appreciated! Cheers.

bengreenow avatar Oct 17 '21 14:10 bengreenow

Hi @bengreenow, thanks for your kind words and your interest in the MIDIMonster (and congratulations on opening the 100th issue)!

As you've correctly guessed, this would be a task best suited for the programming backends, of which only Lua is available for Windows so far.

There might be a way to do a minimal delay between keypresses using the loopback backend (ie. mapping an input to the first key and a loopback channel, then that loopback channel to the second key and a different loopback channel, etc), but that would incur some limitations on the length of the sequence (and it's currently untested).

As for the "best" solution, that would probably be triggering a Lua thread to handle the output sequence. That is, have one channel from the MIDI instance mapped to the Lua instance to trigger the sequence, and then map a set of output channels from the Lua instance to a wininput instance.

An example, off the top of my head and currently untested (will do so tomorrow, so this answer might get updated):

Configuration:

[wininput keys]

[lua sequence]
script = keypress.lua

[midi in]
read = device

[map]
in.ch0.note0 > sequence.trigger
sequence.{t,e,s} > keys.key.{t,e,s}

keypress.lua:

function sequence()
    output("t", 1)
    sleep(10)
    output("t", 0)
    output("e", 1)
    sleep(10)
    output("e", 0)
    output("s", 1)
    sleep(10)
    output("s", 0)
    output("t", 1)
    sleep(10)
    output("t", 0)
end

function trigger(value)
    if value > 0.9 then
        thread(sequence)
    end
end

Hope that helps and gives you an idea of how to solve this! I'll admit its not particularly elegant, especially the Lua script could be done nicer. It's also giving me a few ideas for Lua API's that should maybe exist.

cbdevnet avatar Oct 17 '21 23:10 cbdevnet