Sorry, kid. I don't know what you said but I officially don't give a damn. Good luck with your future endeavors, whatever they may be. Basketweaving, perhaps. It makes no difference to me because people like you are a waste of my time. But take my word, I won't spend another second on people who can't or won't appreciate the value of what they're being offered free of charge.This post was made by Randy Walker who is currently on your ignore list. Display this post.
Intercept the *Return Key*
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Intercept the *Return Key*
Last edited by netmaestro on Thu Feb 09, 2012 7:46 am, edited 1 time in total.
BERESHEIT
Re: Intercept the *Return Key*
Two to beam upnetmaestro wrote:I knew that. Just kidding of course, hehe. (omg, Scotty! Beam me up! Now would be a good time!)Well that may be true but I was talking about my bottle of wine!
Windows 11, Manjaro, Raspberry Pi OS


Re: Intercept the *Return Key*
Code: Select all
Enumeration 1
#String1
#string2
#string3
#string4
#menuQuit
EndEnumeration
OpenWindow(0,#Null,#Null,400,200,"HAI",#PB_Window_ScreenCentered)
StringGadget(#String1,5,5,300,20,"Sting Field 1")
StringGadget(#String2,5,35,300,20,"2 Field String 2")
AddKeyboardShortcut(0,#PB_Shortcut_Escape,#menuQuit)
OpenWindow(1,#Null,#Null,400,200,"HAI",#PB_Window_ScreenCentered)
StringGadget(#String3,5,5,300,20,"Sting Field 3")
StringGadget(#String4,5,35,300,20,"2 Field String 4")
AddKeyboardShortcut(1,#PB_Shortcut_Escape,#menuQuit)
SetActiveGadget(1)
Repeat
event=WaitWindowEvent()
evw = EventWindow()
Select event
Case #PB_Event_Gadget
eventg=EventGadget()
evw = EventWindow()
Select eventg
Case #String1,#string2,#string3,#string4
Select EventType()
Case #PB_EventType_Focus
AddKeyboardShortcut(evw,#PB_Shortcut_Return, eventg)
Case #PB_EventType_LostFocus
RemoveKeyboardShortcut(evw,#PB_Shortcut_Return)
EndSelect
EndSelect
Case #PB_Event_Menu
menu = EventMenu()
Select Menu
Case #String1,#string2,#string3,#string4
MessageRequester("Easy",GetGadgetText(menu)+" See?")
Case #menuQuit
Quit=1
EndSelect
Case #PB_Event_CloseWindow
Quit=1
RemoveKeyboardShortcut(0,#PB_Shortcut_Return)
RemoveKeyboardShortcut(1,#PB_Shortcut_Return)
EndSelect
Until Quit=1
Windows 11, Manjaro, Raspberry Pi OS


Re: Intercept the *Return Key*
That's the idea idle. I don't know why this is so difficult to understand for certain people.
Part of the fun of programming is figuring out how to get your program to perform exactly how you would like.
Part of the fun of programming is figuring out how to get your program to perform exactly how you would like.
----
R Tape loading error, 0:1
R Tape loading error, 0:1
Re: Intercept the *Return Key*
Phew, what a long conversation for just a Return Key...
I went back to the begin (oh, are we going to do it all over again?
) and played with the Return Key my way...
because I think Windows' Return Key is to simulate a click on the default button...
so here my code: (and then we go to bed, aren't we?)
So, even if you are on the TrackbarGadget, the Enter key will press either the Play or Stop button.
The interesting thing here is the addition of the zOclick procedure that emulates a click on a gadget, a procedure I found on the forum a long time ago, however I don't remember who wrote it...
Cheers

I went back to the begin (oh, are we going to do it all over again?

because I think Windows' Return Key is to simulate a click on the default button...
so here my code: (and then we go to bed, aren't we?)

Code: Select all
Procedure zOclick(Gadget.i) ;simulates a click on a gadget
GetCursorPos_(cp.POINT)
GetWindowRect_(GadgetID(Gadget),r.RECT)
SetCursorPos_((r\left+5),(r\top+5))
mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)
SetCursorPos_(cp\x,cp\y)
EndProcedure
#WindowWidth = 390
#WindowHeight = 350
If OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, "PureBasic - Gadget Demonstration",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
Top = 10
GadgetHeight = 24
Frame3DGadget(#PB_Any, 10, Top, 370, 290, "Player...") : Top+20
StringGadget(0, 20, Top, 200, GadgetHeight, "")
PlayTop = Top : ButtonGadget(1, 223, PlayTop, 72, GadgetHeight, "Play",#PB_Button_Default)
StopTop = Top : ButtonGadget(2, 295, StopTop, 72, GadgetHeight, "Stop") : Top+35
TogglePlayStop=0; 0=Play, 1=Stop
DisableGadget(2,1)
GadgetToolTip(1,"Play the current song")
PanelGadget(3, 20, Top, #WindowWidth-50, #WindowHeight-Top-60)
AddGadgetItem(3, 0, "MP3 PlayList")
ListViewGadget(4, 6, 10, 230, 148)
For k=0 To 30
AddGadgetItem(4, -1, "Music Song n° "+Str(k))
Next
ButtonGadget(5, 250, 10, 80, GadgetHeight, "Add")
ButtonGadget(6, 250, 38, 80, GadgetHeight, "Remove")
ButtonGadget(7, 250, 66, 80, GadgetHeight, "Select")
GadgetToolTip(7, "Select the current song")
TrackBarGadget(17, 10, 168, 310, 25, 0, 100)
AddGadgetItem(3, 1, "Options")
Top = 10
CheckBoxGadget(10, 10, Top, 250, GadgetHeight, "Enable low-pass filter") : Top+30
CheckBoxGadget(11, 10, Top, 250, GadgetHeight, "Enable visual plug-in") : Top+30
ComboBoxGadget(12, 10, Top, 250, 21) : Top+30
AddGadgetItem(12, -1, "FireWorks")
AddGadgetItem(12, -1, "OpenGL spectrum")
AddGadgetItem(12, -1, "Bump bass")
SetGadgetState(12,0)
DisableGadget(12,1)
OptionGadget(13, 10, Top, 80, GadgetHeight, "640*480") : Top+20
OptionGadget(14, 10, Top, 80, GadgetHeight, "800*600") : Top+20
OptionGadget(15, 10, Top, 80, GadgetHeight, "1024*768")
SetGadgetState(13, 1)
ButtonGadget(16, 150, Top, 80, GadgetHeight, "Info")
CloseGadgetList()
TextGadget (9, 10, #WindowHeight-30, 250, 24, "PureBasic - Gadget demonstration")
ButtonGadget(8, #WindowWidth-100, #WindowHeight-36, 80, 24, "Quit")
SetGadgetState(3, 0)
AddKeyboardShortcut(0, #PB_Shortcut_Return, 15)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Menu
;
Select EventMenu()
Case 15
If TogglePlayStop=0
xx.s=GetGadgetText(0)
MessageRequester("Info", "Return key pressed, now Playing...", 0)
zOclick(1)
TogglePlayStop ! 1 ; this will toggle
Else
MessageRequester("Info", "Return key pressed, Music stopped!", 0)
zOclick(2)
TogglePlayStop ! 1
EndIf
; EndIf
EndSelect
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Case 1 ; Play
FreeGadget(1)
ButtonGadget(1, 223, PlayTop, 72, GadgetHeight, "Play")
FreeGadget(2)
ButtonGadget(2, 295, StopTop, 72, GadgetHeight, "Stop",#PB_Button_Default)
DisableGadget(2,0) ; Enable the 'Stop' gadget
DisableGadget(1,1) ; Disable the 'Play' Gadget
Case 2 ; Stop
FreeGadget(1)
ButtonGadget(1, 223, PlayTop, 72, GadgetHeight, "Play",#PB_Button_Default)
FreeGadget(2)
ButtonGadget(2, 295, StopTop, 72, GadgetHeight, "Stop")
DisableGadget(1,0) ; Enable the 'Play' gadget
DisableGadget(2,1) ; Disable the 'Stop' Gadget
Case 4
If EventType() = 2
SetGadgetText(0, GetGadgetText(4)) ; Get the current item from the ListView..
EndIf
Case 5 ; Add
AddGadgetItem(4, -1, "New Item Added...")
Case 6 ; Remove
RemoveGadgetItem(4, GetGadgetState(4)) ; Remove the current element of the ListView
Case 7 ; Select
SetGadgetText(0, GetGadgetText(4)) ; Get the current item from the ListView..
Case 8 ; Quit...
Quit = 1
Case 11 ; Enable PlugIn..
DisableGadget(12, 1-GetGadgetState(11))
Case 16 ;
If GetGadgetState(13) : Result$ = GetGadgetText(13) : EndIf
If GetGadgetState(14) : Result$ = GetGadgetText(14) : EndIf
If GetGadgetState(15) : Result$ = GetGadgetText(15) : EndIf
MessageRequester("Info", "Selected screen mode: "+Result$, 0)
Case 17
SetGadgetText(0, Str(GetGadgetState(17)))
EndSelect
EndSelect
Until Quit = 1
EndIf
End
The interesting thing here is the addition of the zOclick procedure that emulates a click on a gadget, a procedure I found on the forum a long time ago, however I don't remember who wrote it...

Cheers
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: Intercept the *Return Key*
No idea why it's so difficult to accept or understand good advise when it's freely given by so many who all clearly know moreem_uk wrote:That's the idea idle. I don't know why this is so difficult to understand for certain people.
Part of the fun of programming is figuring out how to get your program to perform exactly how you would like.
about PB. Oh well, obviously they know better, so they may as well start figuring things out for themselves but I somehow doubt they'll enjoy it!
@charvista
Yes far to long. Scotty will beam you up when your ready!
Last edited by idle on Tue Feb 14, 2012 11:09 pm, edited 1 time in total.
Windows 11, Manjaro, Raspberry Pi OS


Re: Intercept the *Return Key*
In Randy's defense, the last few responses are overlooking a major point (the main point?) of this entire thread...
Randy wants to detect Return key presses and trigger some extra code WHILE STILL letting the gadgets handle Return key events properly. Using AddKeyboardShortcut() alone will prevent some gadgets (ie. EditorGadget, ScintillaGadget, multiline StringGadget...) from handling newlines, etc.
(Right?)
I think this thread is going in circles. Randy seems to want an event structure like this:
This is a valid request, and I think it's been submitted to Feature Requests now. CURRENTLY I think this same behavior can be approximated as:
That last line (sending a "return key" message) would probably require platform-specific API such as SendMessage_(GadgetID(X)), but it should be possible depending on what you specifically want to happen (eg. a text entry field with some "Continue" action on "Return" press, or whatever).
That's all I've got left to contribute...................
Also, for netmaestro, if you are reading this:
Randy wants to detect Return key presses and trigger some extra code WHILE STILL letting the gadgets handle Return key events properly. Using AddKeyboardShortcut() alone will prevent some gadgets (ie. EditorGadget, ScintillaGadget, multiline StringGadget...) from handling newlines, etc.
(Right?)
I think this thread is going in circles. Randy seems to want an event structure like this:
Code: Select all
wait for window event...
if gadget event...
select which gadget...
if eventtype = return_key...
do "this" (in addition to normal return_key behavior)
Code: Select all
add return_key shortcut
wait for window event...
if return_key event (technically "menu" event)
select which gadget (GetActiveGadget())
do "this" (any triggered code)
if gadget type = editor/string/etc
then send return_key message to the gadget itself (to add newlines, etc)
That's all I've got left to contribute...................
Also, for netmaestro, if you are reading this:
Unfortunately you blocked Randy right before he gave a humble/grateful reply... just for your information!netmaestro wrote:Sorry, kid. I don't know what you said but I officially don't give a damn. Good luck with your future endeavors, whatever they may be. Basketweaving, perhaps. It makes no difference to me because people like you are a waste of my time. But take my word, I won't spend another second on people who can't or won't appreciate the value of what they're being offered free of charge.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Intercept the *Return Key*
I know what he wants. Personally, I hope he gets it. But for now, he is simply unable to grasp the logic contsructs necessary to solve the task using existing Purebasic capabilities. That's unfortunate, but I will tell you this: When I take time to write code with no profit motive whatsoever and I end up getting mocked in response, my typing fingers are going to fall silent:Randy wants to detect Return key presses and trigger some extra code WHILE STILL letting the gadgets handle Return key events properly. Using AddKeyboardShortcut() alone will prevent some gadgets (ie. EditorGadget, ScintillaGadget, multiline StringGadget...) from handling newlines, etc.
One day, some tens of years in the future, you will come to understand the value of a mentor. And realize the true price of what your stupid words thoughtlessly pissed away.Randy Walker wrote:Uhhh Ohhhh Where is netmaestro?... I need to talk to him about his perfect workaround solution.
viewtopic.php?f=13&t=49100
Ooopsie Did I say 'workaround' again?
GetActiveGadget() together with EventMenu()? No. The solution I posted added a keyboard shortcut upon receiving the focus event on a string gadget and removed it upon receiving the lostfocust event. This approach affects no other controls in any way and works perfectly in a basic single-window application. For something more complex, all you have to do is anticipate the potential eventualities and code for them. EventGadget() is irrelevant. Could I elaborate? Sure. But I'm not send good keystrokes after bad. I have nothing more to say on this subject.kenmo wrote:if return_key event (technically "menu" event)
select which gadget (GetActiveGadget())
do "this" (any triggered code)
BERESHEIT
Re: Intercept the *Return Key*
Netmaestro, I should have clarified: the first part of my post was mostly in response to charvista's code, which intercepts every single Return press and wouldn't behave well with EditorGadgets or some others. Your method (and Idle's similar method) using gadget focus works fine!
The EventMenu()/GetActiveGadget() approach has also worked fine for me, it all depends on what you want to do with the intercepted shortcuts.
And thanks for calling me a "skilled coder", that's like Euler saying I'm good at mathematics
The EventMenu()/GetActiveGadget() approach has also worked fine for me, it all depends on what you want to do with the intercepted shortcuts.
And thanks for calling me a "skilled coder", that's like Euler saying I'm good at mathematics

-
- Addict
- Posts: 1675
- Joined: Sun Dec 12, 2010 12:36 am
- Location: Somewhere in the midwest
- Contact:
Re: Intercept the *Return Key*
I'm a little disappointed at the behavior displayed in this thread, guys..
I didn't think Randy's position was that untenable, but people have let this get personal and that is a real shame. Neither side is looking really intelligent from my spot over here on the fence.
Don't let things get personal!
I didn't think Randy's position was that untenable, but people have let this get personal and that is a real shame. Neither side is looking really intelligent from my spot over here on the fence.
Don't let things get personal!

-
- 666
- Posts: 1033
- Joined: Mon Sep 01, 2003 2:33 pm
Re: Intercept the *Return Key*
I tend to agree, Randy is getting a bit of a raw deal here. I know he kinda went off on a bit of a crusade, but I think it was purely through frustration. We ALL fly off the handle from time to time and I was one of the worst offenders in the past. As I recall, PureBasic used to detect the enter event on a single line string gadget, and if that behaviour has changed and is still used in the documentation and example code, then the documentation should be changed to reflect that glaring error. I can understand why he got frustrated though, but he certainly does not deserve to be staked out and left for the crows. He's a damn nice lad and I have spoken to him a fair bit recently. Can't we all just make an effort to get along for once?
Ash.
Ash.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Intercept the *Return Key*
Ok, fair enough. No question some of my words were unnecessarily harsh. Sorry for that, Randy. Chalk it up to February I guess.
BERESHEIT
- electrochrisso
- Addict
- Posts: 989
- Joined: Mon May 14, 2007 2:13 am
- Location: Darling River
Re: Intercept the *Return Key*
Sure, things might have got a bit heated on this discussion, but I got a lot of good info about this subject anyhow. 

PureBasic! Purely the best 

-
- 666
- Posts: 1033
- Joined: Mon Sep 01, 2003 2:33 pm
Re: Intercept the *Return Key*
Yeah, there was some very interesting stuff in this and the other related threads
. It could almost do with a moderator bundling it all up into one thread and going on an editing frenzy to clean it up a little lol 


- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Intercept the *Return Key*
One person withdrawing can hardly amount to this. Seriously, I don't wield anything close to that kind of power. I'm one voice in thousands here. But your point is taken and I'll see if I can't manage a more circumspective view of this one going forward. Thanks for your aspect on this, it's appreciated. I guess we've all learned a bit from this topic, temporary as it may be; Someone's going to need to know how to draw a circle on something somewhere and we'll all stampede over there and take up that exciting new challenge. Be there or be square...LuCiFeR[SD] wrote:..but he certainly does not deserve to be staked out and left for the crows.

BERESHEIT