#PB_Event_FirstCustomValue and AddKeyboardShortcut

Just starting out? Need help? Post your questions and find answers here.
Maitre_Kanter
User
User
Posts: 84
Joined: Mon Sep 06, 2010 3:05 pm

#PB_Event_FirstCustomValue and AddKeyboardShortcut

Post by Maitre_Kanter »

Hello everybody,

i have some custom values for events and there is a problem when I use AddKeyboardShortcut().

Code: Select all

Enumeration #PB_Event_FirstCustomValue
    #evt_focusOnTab_0
    #evt_focusOnTab_1
EndEnumeration 

AddKeyboardShortcut(MyWindow, #VK_F1, #evt_focusOnTab_0)
The issue raised at runtime (in french): [ERREUR] AddKeyboardShortcut(): La valeur 'Event' de AddKeyboardShortcut() doit être comprise entre 0 et 64000.

My implementation is not correct ? or may be an issue ?
Last edited by Maitre_Kanter on Wed Mar 09, 2022 4:33 pm, edited 1 time in total.
User_Russian
Addict
Addict
Posts: 1516
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: [PB6bx] #PB_Event_FirstCustomValue and AddKeyboardShortcut

Post by User_Russian »

This is not a bug.
From the help https://www.purebasic.com/documentation ... rtcut.html
Event The number which will be returned by the EventMenu() function. This value has a limited range, from 0 to 64000. By default, a window already has the #PB_Shortcut_Tab and #PB_Shortcut_Tab|#PB_Shortcut_Shift shortcuts to handle tab and shift-tab correctly through the gadgets. A shortcut can be removed with RemoveKeyboardShortcut().
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: [PB6bx] #PB_Event_FirstCustomValue and AddKeyboardShortcut

Post by ChrisR »

A shortcut generates a menu event (between 0 and 64000), not a custom event.
In your declaration, you have to dissociate the menu (shorcut) events enumeration from the custom events.

Code: Select all

Enumeration FormMenu
  #Evt_focusOnTab_0
  #Evt_focusOnTab_1
EndEnumeration

Enumeration EventCustom #PB_Event_FirstCustomValue
  #Evt_My_Custom1
EndEnumeration

AddKeyboardShortcut(MyWindow, #VK_F1, #Evt_focusOnTab_0)

To avoid problems in the enumerations with modules, an organization like the one proposed by ts-soft looks good: Enumeration #PB_Event_FirstCustomValue
Maitre_Kanter
User
User
Posts: 84
Joined: Mon Sep 06, 2010 3:05 pm

[FIXED]: [PB6bx] #PB_Event_FirstCustomValue and AddKeyboardShortcut

Post by Maitre_Kanter »

Thank you for your replies !
Post Reply