Deactivate Buzzer

Everything else that doesn't fall into one of the other PB categories.
KarLKoX
Enthusiast
Enthusiast
Posts: 681
Joined: Mon Oct 06, 2003 7:13 pm
Location: France
Contact:

Deactivate Buzzer

Post 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 :P
"Qui baise trop bouffe un poil." P. Desproges

http://karlkox.blogspot.com/
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

is it possible to add a kb shortcut to a gadget itself?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
KarLKoX
Enthusiast
Enthusiast
Posts: 681
Joined: Mon Oct 06, 2003 7:13 pm
Location: France
Contact:

Post 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 :P
"Qui baise trop bouffe un poil." P. Desproges

http://karlkox.blogspot.com/
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Deactivate Buzzer

Post 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
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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 :wink:

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
BERESHEIT
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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. :P

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? :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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)
BERESHEIT
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

:lol:
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply