New constant #PB_Shortcut for BindMenuEvent

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

New constant #PB_Shortcut for BindMenuEvent

Post 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!
BERESHEIT
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: New constant #PB_Shortcut for BindMenuEvent

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: New constant #PB_Shortcut for BindMenuEvent

Post by davido »

+1

@netmaestro - Nice workaround!
DE AA EB
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: New constant #PB_Shortcut for BindMenuEvent

Post 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
Post Reply