|
|
|
04-23-2021, 06:30 AM
|
#1
|
Human being with feelings
Join Date: Jan 2021
Location: Paris
Posts: 255
|
gfx intercept keys
Hi everybody
When the focus is on gfx window, Reaper don't receive keys information.
For example if I run this simple window script :
Code:
local function Main()
local char = gfx.getchar()
if char ~= 27 and char ~= -1 then
reaper.defer(Main)
end
gfx.update()
end
gfx.init("My Window", 640, 480, 0, 200, 200)
Main()
And if the focus is on it, then I can't use my Reaper shortcuts. I have to click in the main window to give the focus back to Reaper.
Is there a way to get around this?
For example by getting the key information in the script and sending it back to Reaper ? Maybe with JS API ?
Thanks in advance
|
|
|
04-23-2021, 06:48 AM
|
#2
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,630
|
Not an easy one and it's actually better that way.
Imagine you type a text into the gfx-window and every single character would also be run as action.
This would create a mess and ruin your project.
In your code, it would be impossible to run the action for esc, so at least this is not feasible.
You could try to hardcode the shortcuts, so you can run the action via the Main_OnCommand-function, when a certain key is pressed.
You can bind them also to shortcuts but this involves analyzing the shortcuts in the reaper-kb.ini file to run them via Main_OnCommand, but this is tedious.
But you would also need to know, if you want to run the actions of Main, Midi, MediaExplorer-context, which can become quite tedious as well.
Edit:
You could use gfx_mousecap as way to close the window. This stores, if you click via mouse but also if you've pressed shift or alt or ctrl.
So you could code as alternative closing the window using the shift-key instead of esc and therefore circumvent the problem altogether.
Last edited by Meo-Ada Mespotine; 04-23-2021 at 06:54 AM.
|
|
|
04-23-2021, 07:07 AM
|
#3
|
Human being with feelings
Join Date: Jan 2021
Location: Paris
Posts: 255
|
Thanks Meo-Ada Mespotine
When I read you it seems difficult...
Isn't there a simpler solution based on : - I get the key information with JS_VKeys_GetState()
- Then I send it back to Reaper with JS_WindowMessage_Send() ?
Of course I want do it in a script which does not need keys. We could also imagine to return all the keys EXCEPT some like 'Escape'.
|
|
|
04-23-2021, 08:50 AM
|
#4
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,630
|
You could try to use catch the esc-key only for the gfx-window itself using JS-extension, but I have no idea how to do it and if that works.
Best is to ask in the JS-extension thread for it.
|
|
|
04-23-2021, 11:55 AM
|
#5
|
Human being with feelings
Join Date: Sep 2008
Location: Sweden
Posts: 7,432
|
Quote:
Originally Posted by Rodilab
Hi everybody
When the focus is on gfx window, Reaper don't receive keys information.
For example if I run this simple window script :
Code:
local function Main()
local char = gfx.getchar()
if char ~= 27 and char ~= -1 then
reaper.defer(Main)
end
gfx.update()
end
gfx.init("My Window", 640, 480, 0, 200, 200)
Main()
And if the focus is on it, then I can't use my Reaper shortcuts. I have to click in the main window to give the focus back to Reaper.
Is there a way to get around this?
For example by getting the key information in the script and sending it back to Reaper ? Maybe with JS API ?
Thanks in advance
|
I battled a lot with this focus stealing issue in my MFXlist script, and I could not really find any satisfying way around it. The way I do it now is the script sets the focus to the arrange window after every mouse click in my script window (except in special cases), but this prevents ESC from closing the script so I added a right-click menu to the script to close it.
Note that the script implementing action calls on common key strokes is not the way to go, in my opinion, for two reasons:
1. People may redefine what is considered common, for interlace spacebar to pause instead of stop.
2. Even if you manage to implement the common key strokes satisfactorily, there are so many of them...
An API call to pass unwanted key strokes on to Reaper is really missing.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
|
|
|
09-22-2021, 08:35 AM
|
#6
|
Human being with feelings
Join Date: Jan 2013
Posts: 1,128
|
If you never want your script to have focus, this works well:
Code:
function PreventFocusSteal(scriptname)
local focused_wind = reaper.JS_Window_GetFocus()
local script_HWND = reaper.JS_Window_Find(scriptname, true)
if focused_wind == script_HWND then
reaper.SetCursorContext(1) --Focus Arrange Window
end
end
Last edited by lexaproductions; 09-22-2021 at 09:47 AM.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 07:56 AM.
|