Old 04-23-2021, 06:30 AM   #1
Rodilab
Human being with feelings
 
Rodilab's Avatar
 
Join Date: Jan 2021
Location: Paris
Posts: 255
Default 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
Rodilab is offline   Reply With Quote
Old 04-23-2021, 06:48 AM   #2
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,630
Default

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.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...

Last edited by Meo-Ada Mespotine; 04-23-2021 at 06:54 AM.
Meo-Ada Mespotine is offline   Reply With Quote
Old 04-23-2021, 07:07 AM   #3
Rodilab
Human being with feelings
 
Rodilab's Avatar
 
Join Date: Jan 2021
Location: Paris
Posts: 255
Default

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'.
Rodilab is offline   Reply With Quote
Old 04-23-2021, 08:50 AM   #4
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,630
Default

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.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 04-23-2021, 11:55 AM   #5
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 7,432
Default

Quote:
Originally Posted by Rodilab View Post
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...
Fabian is offline   Reply With Quote
Old 09-22-2021, 08:35 AM   #6
lexaproductions
Human being with feelings
 
Join Date: Jan 2013
Posts: 1,128
Default

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.
lexaproductions is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:56 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.