Page 1 of 1

New constant #PB_Shortcut for BindMenuEvent

Posted: Mon Oct 07, 2013 5:52 am
by netmaestro
Consider the following snippet:

Code: Select all

Procedure callback1()
  Debug "Right-arrow key pressed"  
EndProcedure

OpenWindow(0,0,0,800,600,"Game",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
AddKeyboardShortcut(0, #PB_Shortcut_Right, 1)

CreatePopupMenu(0) ; dummy, we'll never add items to it or show it
                   ; it exists only to allow the use of BindMenuEvent

BindMenuEvent(0, 1, @callback1())

Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow
Here it was necessary to create a dummy popupmenu to allow the use of BindMenuEvent with AddKeyboardShortcut. If we could write:

Code: Select all

BindMenuEvent(#PB_Shortcut, <event>, @<callback>)
then... well, you get the idea. Thanks for listening!

Re: New constant #PB_Shortcut for BindMenuEvent

Posted: Mon Oct 07, 2013 6:06 am
by ts-soft
+1

workaround:

Code: Select all

Procedure callback1()
  Debug "Right-arrow key pressed" 
EndProcedure

OpenWindow(0,0,0,800,600,"Game",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
AddKeyboardShortcut(0, #PB_Shortcut_Right, 1)

; CreatePopupMenu(0) ; dummy, we'll never add items to it or show it
;                    ; it exists only to allow the use of BindMenuEvent

;BindMenuEvent(0, 1, @callback1())
BindEvent(#PB_Event_Menu, @callback1(), 0, 1)

Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: New constant #PB_Shortcut for BindMenuEvent

Posted: Mon Oct 07, 2013 7:55 am
by davido
+1

@netmaestro - Nice workaround!

Re: New constant #PB_Shortcut for BindMenuEvent

Posted: Mon Oct 07, 2013 8:51 am
by Danilo
ts-soft wrote:+1

workaround:
Doesn't look like a workaround. Keyboard Shortcuts just use Menu events.

Code: Select all

Procedure callback1()
  Debug "Right-arrow key pressed" 
EndProcedure

OpenWindow(0,0,0,800,600,"Game",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
AddKeyboardShortcut(0, #PB_Shortcut_Right, 1)
BindEvent(#PB_Event_Menu, @callback1(), 0, 1)

Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow