Page 1 of 1
					
				Why is the button not activated by pressing return ?
				Posted: Fri Feb 24, 2012 11:58 am
				by infratec
				Hi,
I just discoverd, that a ButtonGadget() is not activated by pressing return if the button
is the active gadget.
Is this normal ?
What can I do to make it behave as I want ?
(PB 4.60 Win 32)
Code: Select all
OpenWindow(0, 0, 0, 120, 40, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ButtonGadget(0, 10, 10, 100, 20, "Press return")
SetActiveGadget(0)
Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget
    If EventGadget() = 0
      Debug "Pressed"
    EndIf
  EndIf
Until Event = #PB_Event_CloseWindow
Bernd
 
			 
			
					
				Re: Why is the button not activated by pressing return ?
				Posted: Fri Feb 24, 2012 12:14 pm
				by Little John
				infratec wrote:Hi,
I just discoverd, that a ButtonGadget() is not activated by pressing return if the button
is the active gadget.
Is this normal ?
Hi,
as far as I know this is normal. At lest on Windows, we are supposed to press [Space] instead of [Return]. 
infratec wrote:What can I do to make it behave as I want ?
(PB 4.60 Win 32)
I use AddKeyboardShortcut() to make it behave that way.
Regards, Little John
 
			 
			
					
				Re: Why is the button not activated by pressing return ?
				Posted: Fri Feb 24, 2012 12:20 pm
				by infratec
				Hm,
ok, AddKeyboardShortcut() is a solution.
But the MessageRequester() buttons from Windows (for example) works with return.
So I thought that also the buttons of PB are working with return and not with space  
 
Bernd
 
			 
			
					
				Re: Why is the button not activated by pressing return ?
				Posted: Fri Feb 24, 2012 12:22 pm
				by Fangbeast
				Hi, I just discoverd, that a ButtonGadget() is not activated by pressing return if the button is the active gadget. Is this normal ? What can I do to make it behave as I want ?
As far as I can see, buttongadgets don't generate events upon given focus, not like a string gadget or list/listicon, they just become the active gdadget.
I found this code in the forum to generate events to send to gadgets though, from a post by t57042
(PB 4.60 Win 32)
Import "gadget.lib"
   PB_Gadget_SendGadgetCommand(hWnd, EventType)
EndImport
PB_Gadget_SendGadgetCommand(GadgetID(1), #PB_EventType_LeftClick)
 
			 
			
					
				Re: Why is the button not activated by pressing return ?
				Posted: Fri Feb 24, 2012 12:36 pm
				by RASHAD
				Hi everyone
@infratec I just used the document example
There is no mention for #PB_EventType_ReturnKey as you can see
Next is for Windows
Code: Select all
OpenWindow(0, 0, 0, 120, 40, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ButtonGadget(0, 10, 10, 100, 20, "Press return")
SetActiveGadget(0)
Repeat
       Event = WaitWindowEvent()       
       Select Event       
        Case #PB_Event_Gadget
           Select EventGadget()
             Case 0
               Select EventType()               
                 Case #PB_EventType_LeftClick        : Debug "Click with left mouse button"
                 Case #PB_EventType_RightClick       : Debug "Click with right mouse button"
                 Case #PB_EventType_LeftDoubleClick  : Debug "Double-click with left mouse button"
                 Case #PB_EventType_RightDoubleClick : Debug "Double-click with right mouse button"
               EndSelect
           EndSelect
           
        Case #WM_CHAR
          Select EventwParam()
            Case 13
                AG = GetActiveGadget()
                PostMessage_(GadgetID(AG), #WM_LBUTTONDOWN, 0, 0)
                PostMessage_(GadgetID(AG), #WM_LBUTTONUP, 0, 0)
          EndSelect
      
       EndSelect
     Until Event = #PB_Event_CloseWindow
 
			 
			
					
				Re: Why is the button not activated by pressing return ?
				Posted: Fri Feb 24, 2012 12:40 pm
				by infratec
				RASHAD wrote:
There no mention for #PB_EventType_ReturnKey as you can see
Yes,
but why it works with the space key ?
Btw. thanks for your code.
But to be crosscompatible I will use AddKeyboardShortcut() and put all my button event stuff in 
own procedures.
 
			 
			
					
				Re: Why is the button not activated by pressing return ?
				Posted: Fri Feb 24, 2012 12:41 pm
				by Little John
				This is an example how I use to solve the problem:
Code: Select all
EnableExplicit
;-- Windows
Enumeration
   #MyWin
EndEnumeration
;-- Gadgets
Enumeration
   #Btn_Ok
EndEnumeration
;-- Keys for shortcuts
Enumeration 1
   #KeyReturn
EndEnumeration
Define Event, Gadget
OpenWindow(#MyWin, 0, 0, 120, 40, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ButtonGadget(#Btn_Ok, 10, 10, 100, 20, "OK")
SetActiveGadget(#Btn_Ok)
AddKeyboardShortcut(#MyWin, #PB_Shortcut_Return, #KeyReturn)
Repeat
   Event = WaitWindowEvent()
   Gadget = EventGadget()
   
   If Event = #PB_Event_Menu
      If EventMenu() = #KeyReturn
         Event = #PB_Event_Gadget
         If GetActiveGadget() = #Btn_Ok
            Gadget = #Btn_Ok
         EndIf               
      EndIf
   EndIf
   
   If Event = #PB_Event_Gadget
      If Gadget = #Btn_Ok
         Debug "'OK' pressed"
      EndIf   
   EndIf
Until Event = #PB_Event_CloseWindow
Regards, Little John
 
			 
			
					
				Re: Why is the button not activated by pressing return ?
				Posted: Fri Feb 24, 2012 12:43 pm
				by RASHAD
				
 
I never noticed that or maybe I forget about that after long time
I think the team have some problems with the Return Key and different types of
objects
 
			 
			
					
				Re: Why is the button not activated by pressing return ?
				Posted: Sun Mar 11, 2012 10:34 pm
				by Randy Walker
				Variation of the above.  (but no libs required and still using Windows API stuff)
You can actually *see* the button move.
Code: Select all
OpenWindow(0, 0, 0, 120, 40, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ButtonGadget(0, 10, 10, 100, 20, "Press return")
SetActiveGadget(0)
Repeat
  Event = WaitWindowEvent()
  Select Event       
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Select EventType()               
            Case #PB_EventType_LeftClick        : Debug "Click with left mouse button"
            Case #PB_EventType_RightClick       : Debug "Click with right mouse button"
            Case #PB_EventType_LeftDoubleClick  : Debug "Double-click with left mouse button"
            Case #PB_EventType_RightDoubleClick : Debug "Double-click with right mouse button"
          EndSelect
      EndSelect
      
    Case #WM_CHAR
      Select EventwParam()
        Case 13
          keybd_event_(#VK_SPACE,0,0,0)
          WaitWindowEvent()
          WaitWindowEvent()
          WaitWindowEvent()
          keybd_event_(#VK_SPACE,0,0,0)
          keybd_event_(#VK_SPACE,0,#KEYEVENTF_KEYUP,0)
          
      EndSelect
      
  EndSelect
Until Event = #PB_Event_CloseWindow
 
			 
			
					
				Re: Why is the button not activated by pressing return ?
				Posted: Mon Mar 12, 2012 4:01 pm
				by charvista
				@Bernd,
This way you can have the exact same effect as the MessageRequester.
As it uses API, it is Windows only.
Code: Select all
Procedure zOclick(Gadget.i)
      GetCursorPos_(cp.POINT)
      GetWindowRect_(GadgetID(Gadget),r.RECT)
      SetCursorPos_((r\left),(r\top))
      mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
      mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)
      SetCursorPos_(cp\x,cp\y)
EndProcedure
Win=OpenWindow(#PB_Any, 0, 0, 320, 240, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
    BtnOk=ButtonGadget(#PB_Any, 10, 180, 88, 26, "OK", #PB_Button_Default)
    AddKeyboardShortcut(Win, #PB_Shortcut_Return, 13)
    SetActiveGadget(BtnOk)
    MessageRequester("Real MessageRequester","This is the real MessageRequester")
    Repeat
        Event = WaitWindowEvent()
        Select Event
            Case #PB_Event_Menu
                Select EventMenu()
                    Case 13
                        zOclick(BtnOk)
                EndSelect  
            Case #PB_Event_Gadget
                Select EventGadget()
                    Case BtnOk
                        Debug "Pressed"
                EndSelect
        EndSelect
    Until Event = #PB_Event_CloseWindow
- Clicking on OK works.
- Pressing Space works.
- Pressing Return works.
The procedure zOclick simulates a mouse click.
Additionally, the flag #PB_Button_Default on the button definition gives the appearance of a default button.
Cheers!