how can I add shortcuts for buttons?
how can I add shortcuts for buttons?
Example I have OK, left, right buttons and I want keyboard shortcuts ENTER, left arrow, right arrow to join my buttons?
Registered user of PB (on Linux Mint 21.1 & Win 10 64bit)
Re: how can I add shortcuts for buttons?
Hi,
maybe this can help you out
cheers ~ Vera
maybe this can help you out
Code: Select all
If OpenWindow(0, 0, 0, 130, 90, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(1, 20, 20, 90, 22, "button")
ButtonGadget(2, 20, 50, 90, 22, "button 2")
AddKeyboardShortcut(0, #PB_Shortcut_Return, 0) ; assign enter-key
AddKeyboardShortcut(0, #PB_Shortcut_Up, 1) ; assign up-key
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Debug "button clicked"
Case 2
Debug "button 2 clicked"
EndSelect
Case #PB_Event_Menu
If EventMenu() = 0 And GetActiveGadget() = 1 ; if enter-key while button has the focus
Debug "enter was pressed"
ElseIf EventMenu() = 1 And GetActiveGadget() = 2 ; if up-key while button2 has the focus
Debug "up-key was pressed"
EndIf
EndSelect
Until Event = #PB_Event_CloseWindow
EndIfTwo growing code-collections: WinApi-Lib by RSBasic ~ LinuxAPI-Lib by Omi
Missing a download-file on the forums? ~ check out this backup page.
Missing a download-file on the forums? ~ check out this backup page.
Re: how can I add shortcuts for buttons?
Please be aware that Windows (and possibly other OS) uses the enter and arrow keys for keyboard navigation as an alternative to/in addition to the mouse, so if it's a windowed app you may want to use some other keys instead. (windowed games, and fullscreen games or fullscreen apps are usually the exception) If you must use them, then allow the user to enable/disable them so they can choose instead.sartic wrote:Example I have OK, left, right buttons and I want keyboard shortcuts ENTER, left arrow, right arrow to join my buttons?

