View Single Post
Old 09-08-2019, 12:09 PM   #13
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by Arthur McArthur View Post
Using VKEYS from JS API, create a bit of code that I can add on to scripts (such as those created with Lokasenna GUI) that intercepts all keyboard input and passes it through to optionally either the main window, MIDI editor or Media Explorer. Except for additionally defined keys that would not be passed through but are mapped to the script's functions (I'm fine with copying and pasting this code for each key that I need). So, for example, the code would pass all keyboard input to the MIDI editor, except for W,A,S,D, which would trigger functions within the script.
This one may be a bit more tricky, since gfx.getchar() returns input as something like Unicode/UTF8, and don't return modifier keys such as Ctrl. Unicode has to be converted to Virtual Key Codes to send them to other windows.

Perhaps the easiest would be to ensure that keyboard focus is always on the other window (main, MIDI and Explorer), never on the script GUI, so that REAPER automatically sends all keyboard input to the other window. Then use JS_VKeys instead of gfx.getchar() to intercept and block those few keys that are needed by the script. The virtual key codes can be found here: https://docs.microsoft.com/en-us/win...tual-key-codes. NB: VKeys cannot block keystrokes that are global shortcuts.

When the script starts, get the HWND of the script GUI, and the HWND of the other window:
Code:
reaper.VKeys_Intercept(0x57, 1) -- W
reaper.VKeys_Intercept(0x41, 1) -- A
myHWND = reaper.JS_Window_FindTop("My unique GUI name", true)
-- Get the target window HWND: otherHWND = reaper.MIDIEditor_GetActive(), or reaper.GetMainHwnd(), or reaper.OpenMediaExplorer("", false)
Add this to the deferred loop function:
Code:
if reaper.JS_Window_GetFocus() == myHWND then -- perhaps GetForeground would work as well?
    reaper.JS_Window_SetFocus(otherHWND)
end
keys = reaper.JS_VKeys_GetState(-1) -- Only get keys that were pressed within the last second
if keys:byte(0x57) ~= 0 then
    -- Do W stuff ... same for other keys
end
When the script exits:
Code:
reaper.JS_VKeys_Intercept(0x47, -1)
-- etc for all the keys
juliansader is offline   Reply With Quote