Page 1 of 1
Deactivate Buzzer
Posted: Fri Aug 11, 2006 6:19 pm
by KarLKoX
Hi !
I ve a very simple request : how to deactivate the buzzer when the ENTER key is pressed on a StringGadget ?
You were warned

Posted: Fri Aug 11, 2006 6:50 pm
by netmaestro
...and the very simple answer:
Code: Select all
AddKeyboardShortcut(0, #PB_Shortcut_Return, 1)
You don't have to manage the shortcut in your loop unless you want to, make it process a tab or something, it's up to you. Just keep in mind it's using up menuitem #1, so if you have any menus you'll want to choose a number that doesn't conflict. The 0 is your #window.
Posted: Fri Aug 11, 2006 7:08 pm
by dracflamloc
is it possible to add a kb shortcut to a gadget itself?
Posted: Fri Aug 11, 2006 7:48 pm
by netmaestro
I'm not sure exactly what it is you mean, but if it's along the lines of using a gadget from the keyboard, you can do this:
Code: Select all
OpenWindow(0,0,0,320,120,"Shhhhh....",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
StringGadget(0,20,40,200,20,"")
ButtonGadget(1,20,80,200,20,"Push me or press CTRL-B")
AddKeyboardShortcut(0, #PB_Shortcut_Return, 1)
AddKeyboardShortcut(0, #PB_Shortcut_Control|#PB_Shortcut_B, 2)
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_Event_Menu
Select EventMenu()
Case 2
SendMessage_(GadgetID(1), #WM_LBUTTONDOWN,0,0)
Delay(200)
SendMessage_(GadgetID(1), #WM_LBUTTONUP,0,0)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Debug "Button pushed"
EndSelect
EndSelect
Until EventID = #WM_CLOSE
If that's not what you're after, could you clarify further? As a rule though, keyboard accelerators (or keyboardshortcuts in PB) get applied at the application level.
Posted: Fri Aug 11, 2006 10:39 pm
by KarLKoX
Nice ! This works as i expected, i didn't think that adding a shortcut will disable the buzzer, now, i know that

Thanks

Re: Deactivate Buzzer
Posted: Sat Aug 12, 2006 1:02 am
by PB
From 4 years ago:
http://www.purebasic.fr/english/viewtopic.php?t=3802
My tip in the link above is preferred because netmaestro's tip won't allow
you to use the Enter key anywhere else in your app, without major gadget
handling code, because it effectively disables the Enter key. Take a look:
Code: Select all
OpenWindow(0,0,0,320,200,"Shhhhh....",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
StringGadget(0,20,40,200,20,"")
ButtonGadget(1,20,80,200,20,"Push me or press CTRL-B")
EditorGadget(2,20,120,200,60) : SetGadgetText(2,"Focus me and try to hit Enter")
AddKeyboardShortcut(0, #PB_Shortcut_Return, 1)
AddKeyboardShortcut(0, #PB_Shortcut_Control|#PB_Shortcut_B, 2)
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_Event_Menu
Select EventMenu()
Case 2
SendMessage_(GadgetID(1), #WM_LBUTTONDOWN,0,0)
Delay(200)
SendMessage_(GadgetID(1), #WM_LBUTTONUP,0,0)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Debug "Button pushed"
EndSelect
EndSelect
Until EventID = #WM_CLOSE
Posted: Sat Aug 12, 2006 2:21 am
by netmaestro
Nothing's disabled, the menuevent assigned to the enter key is wide open to use any way you want. And the #PB_String_MultiLine is no longer supported, which forced your switch to #ES_MULTILINE, something that isn't documented for the string gadget and can't be considered futureproof. But - by all means prefer any solution that appeals to you
Here's how to use the shortcut for selected gadget(s), leaving the return key to process normally for any and all other gadgets:
Code: Select all
OpenWindow(0,0,0,250,280,"Shhhhh....",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
StringGadget(0,20,10,200,20,"")
EditorGadget(3,20,40,200,200)
AddKeyboardShortcut(0, #PB_Shortcut_Return, 1)
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_Event_Menu
Select EventMenu()
Case 1
If GetActiveGadget() <> 0
SendMessage_(GadgetID(GetActiveGadget()), #WM_KEYDOWN, #VK_RETURN, 0)
SendMessage_(GadgetID(GetActiveGadget()), #WM_KEYUP, #VK_RETURN, 0)
EndIf
EndSelect
EndSelect
Until EventID = #WM_CLOSE
Posted: Sat Aug 12, 2006 3:13 am
by PB
> Nothing's disabled
I said "effectively disabled" which means it can't be used unless you take
other steps to keep it working, which you later did in your new code.
> #ES_MULTILINE, something that isn't documented for the string gadget
> and can't be considered futureproof
It's part of the Win32 API so it is actually supported and futureproof, unless
Fred decides to remove the "flags" parameter from StringGadgets.
Your new code is a good way of doing it, but until you showed it, newbies
might have had trouble with the Enter key, which is why I made my post.
I didn't want someone to reply here and say "I used netmaestro's code
but now I can't hit Enter in my EditorGadget" etc. See?

Posted: Sat Aug 12, 2006 3:22 am
by netmaestro
Good point, someone would eventually have posted that their enter key's broke now, help! I just wasn't sure why they took the multiline flag away from stringgadgets and when that happens it makes me a bit nervous about applying it another way. Anyway I like your solution too, it's good.
And a third way: turn off the speakers
Fourth way: earplugs
Fifth... (goes on for 384 more ways before falling asleep)
Posted: Sat Aug 12, 2006 4:26 am
by PB