Old 03-25-2020, 12:52 PM   #1
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 93
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 Yesterday, 02:43 PM   #2
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 93
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 Yesterday, 05:59 PM   #3
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,084
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
v6.03+dev0114 - January 14 2020 • Mac 10.12.+ • i7 Quad 2.9GHz • 24GB
Thonex is online now   Reply With Quote
Old Today, 05:09 AM   #4
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 93
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 Today, 06:45 AM   #5
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,700
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
amagalma is online now   Reply With Quote
Old Today, 08:34 AM   #6
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 93
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 Today, 01:23 PM   #7
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,084
Default

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

Bookmarked!

Thanks for sharing.
__________________
Cheers,
Andrew K
v6.03+dev0114 - January 14 2020 • Mac 10.12.+ • i7 Quad 2.9GHz • 24GB
Thonex is online now   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 01:25 PM.


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