Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 03-25-2020, 12:52 PM   #1
cohler
Banned
 
Join Date: Dec 2018
Posts: 642
Default Using Return key (ascii 13) to click a button in Lokasenna GUI

Is there a simple way to do this using the Lokasenna GUI?

I don't find any hooks for this in the code...
cohler is offline   Reply With Quote
Old 04-01-2020, 02:43 PM   #2
cohler
Banned
 
Join Date: Dec 2018
Posts: 642
Default Solved

Added this line of code to Core.lua in GUI.Main_Update_Sate:

Code:
GUI.char = gfx.getchar()
if GUI.char == 13 and GUI.ReturnSubmit then GUI.ReturnSubmit() end   ---ADDED
Then in calling routine that sets up window:

Code:
local submit = GUI.New("submit", "Button", 1, 48, 200, 200, 20, "OK", getval)
GUI.ReturnSubmit = getval  --- ADDED
cohler is offline   Reply With Quote
Old 04-01-2020, 05:59 PM   #3
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Hi cohler,

I'm not sure if I'm following you.

Are you saying that with your code I could have a GUI button respond to the Return key? So hitting "Return" would behave as if the button was clicked?

Thanks.

Cheers,

Andrew K
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
Thonex is offline   Reply With Quote
Old 04-02-2020, 05:09 AM   #4
cohler
Banned
 
Join Date: Dec 2018
Posts: 642
Default

Quote:
Originally Posted by Thonex View Post
Hi cohler,

I'm not sure if I'm following you.

Are you saying that with your code I could have a GUI button respond to the Return key? So hitting "Return" would behave as if the button was clicked?

Thanks.

Cheers,

Andrew K
Yes, exactly.
cohler is offline   Reply With Quote
Old 04-02-2020, 06:45 AM   #5
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,450
Default

Quote:
Originally Posted by cohler View Post
Added this line of code to Core.lua in GUI.Main_Update_Sate:

Code:
GUI.char = gfx.getchar()
if GUI.char == 13 and GUI.ReturnSubmit then GUI.ReturnSubmit() end   ---ADDED
Then in calling routine that sets up window:

Code:
local submit = GUI.New("submit", "Button", 1, 48, 200, 200, 20, "OK", getval)
GUI.ReturnSubmit = getval  --- ADDED
If you add it in Core.lua then ALL scripts in your system that use Lokasenna's GUI will have it. Don't do it!

Add whatever you want in the GUI.func instead.

Code:
Function Whatever()
  -- Check for ESC
  -- Remind me to drink tea at 5 o clock
  -- Free Willy
end

GUI.func = Whatever
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 04-02-2020, 08:34 AM   #6
cohler
Banned
 
Join Date: Dec 2018
Posts: 642
Default

Quote:
Originally Posted by amagalma View Post
If you add it in Core.lua then ALL scripts in your system that use Lokasenna's GUI will have it. Don't do it!

Add whatever you want in the GUI.func instead.

Code:
Function Whatever()
  -- Check for ESC
  -- Remind me to drink tea at 5 o clock
  -- Free Willy
end

GUI.func = Whatever
The if statement added to Core.lua won't affect anything unless you define the function in your main code. That's why I wrote it that way. I don't see how your suggestion could even work.

You need to be checking for the return key in the function that is inside the GUI that checks for keystrokes, which is exactly what I did.

Pray tell with some actual code how your suggestion could possibly even work?
cohler is offline   Reply With Quote
Old 04-02-2020, 01:23 PM   #7
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
Default

Quote:
Originally Posted by cohler View Post
Yes, exactly.
Great!!

Bookmarked!

Thanks for sharing.
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
Thonex is offline   Reply With Quote
Old 04-02-2020, 02:04 PM   #8
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,450
Default

Quote:
Originally Posted by cohler View Post
The if statement added to Core.lua won't affect anything unless you define the function in your main code. That's why I wrote it that way. I don't see how your suggestion could even work.

You need to be checking for the return key in the function that is inside the GUI that checks for keystrokes, which is exactly what I did.

Pray tell with some actual code how your suggestion could possibly even work?

A GUI update by Lokasenna on ReaPack will overwrite your code in Core.lua.


Try this:

Code:
function MyFunc()
  if GUI.char == GUI.chars.RETURN then reaper.ShowConsoleMsg("return\n") end
end


GUI.func = MyFunc
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 04-02-2020, 03:37 PM   #9
cohler
Banned
 
Join Date: Dec 2018
Posts: 642
Default

Quote:
Originally Posted by amagalma View Post
A GUI update by Lokasenna on ReaPack will overwrite your code in Core.lua.


Try this:

Code:
function MyFunc()
  if GUI.char == GUI.chars.RETURN then reaper.ShowConsoleMsg("return\n") end
end


GUI.func = MyFunc
That does not do what my code does. That prints a message on the console when somebody calls GUI.func.

The code I gave executes the Submit button return function when a person presses the return key.

Totally different.

Lokasenna GUI V2 is not being updated anymore. But in any case, you don't need to get it from ReaPack, you can simply embed the code in your own system.
cohler is offline   Reply With Quote
Old 04-02-2020, 08:18 PM   #10
cohler
Banned
 
Join Date: Dec 2018
Posts: 642
Default

Quote:
Originally Posted by amagalma View Post
A GUI update by Lokasenna on ReaPack will overwrite your code in Core.lua.


Try this:

Code:
function MyFunc()
  if GUI.char == GUI.chars.RETURN then reaper.ShowConsoleMsg("return\n") end
end


GUI.func = MyFunc
Tried this and it doesn't work. GUI.char does not maintain the keystroke data at this point in the code.
cohler 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 12:55 AM.


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