Page 1 of 2
First custom event
Posted: Sat Mar 07, 2026 7:12 am
by coco2
Code: Select all
Enumeration CustomEvents #PB_Event_FirstCustomValue
#EventMainKeyboardCtrlN
#EventMainKeyboardCtrlO
#EventMainKeyboardCtrlQ
#EventMainKeyboardESC
#EventMainKeyboardF5
#EventNewKeyboardReturn
#EventNewSectionKeyboardReturn
EndEnumeration
Then when I try this:
Code: Select all
AddKeyboardShortcut(#WindowMain, #PB_Shortcut_Control | #PB_Shortcut_N, #EventMainKeyboardCtrlN)
I get the error:
The 'Event' value of AddKeyboardShortcut() has to be between 0 and 64000
The value of #PB_Event_FirstCustomValue is 65536. What am I doing wrong?
Re: First custom event
Posted: Sat Mar 07, 2026 7:55 am
by jacdelad
Exactly what the error message says: your value is too high.
The event is for events, you are using it for shortcuts. There are no reserved shortcuts, so just start your enumeration at 0 or 1.
Re: First custom event
Posted: Sat Mar 07, 2026 8:13 am
by coco2
Are you sure, it's definitely an event according to the syntax:
AddKeyboardShortcut(#Window, Shortcut, Event)
When I set it as starting at 0 I get unusual behaviour. #EventNewKeyboardReturn works but #EventNewSectionKeyboardReturn doesn't. It just closes the window the shortcut is assigned to.
Re: First custom event
Posted: Sat Mar 07, 2026 8:16 am
by breeze4me
The event parameter is actually a menu item ID. That's why the restriction applies.
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.
The value returned by the EventMenu() function is a menu item ID.
https://www.purebasic.com/documentation ... uitem.html
MenuItemID : A number to identify this menu item in events and commands like SetMenuItemState(). This value should be between 0 and 65535.
Re: First custom event
Posted: Sat Mar 07, 2026 8:18 am
by coco2
When I do this:
Code: Select all
Enumeration Events
#EventMainKeyboardCtrlN
#EventMainKeyboardCtrlO
#EventMainKeyboardCtrlQ
#EventMainKeyboardESC
#EventMainKeyboardF5
#EventNewKeyboardReturn
#EventNewSectionKeyboardReturn = 10
EndEnumeration
it works, but when I delete the "= 10" it fails.
Re: First custom event
Posted: Sat Mar 07, 2026 8:33 am
by breeze4me
coco2 wrote: Sat Mar 07, 2026 8:18 am
When I do this:
Code: Select all
Enumeration Events
#EventMainKeyboardCtrlN
#EventMainKeyboardCtrlO
#EventMainKeyboardCtrlQ
#EventMainKeyboardESC
#EventMainKeyboardF5
#EventNewKeyboardReturn
#EventNewSectionKeyboardReturn = 10
EndEnumeration
it works, but when I delete the "= 10" it fails.
The constant enumeration named "Events" should be deleted if an enumeration with the same name already exists, as its values would be appended to the existing ones.
To name a constant enumeration, its values must be sequential menu item IDs, so it should be named something like “Enumeration MenuItemID”.
Code: Select all
Enumeration ;MenuItemID
#EventMainKeyboardCtrlN
#EventMainKeyboardCtrlO
#EventMainKeyboardCtrlQ
#EventMainKeyboardESC
#EventMainKeyboardF5
#EventNewKeyboardReturn
#EventNewSectionKeyboardReturn = 10
EndEnumeration
#WindowMain = 0
#WindowMain1 = 1
If OpenWindow(#WindowMain, 200, 200, 200, 100, "")
OpenWindow(#WindowMain1, 200, 200, 200, 100, "", #PB_Window_ScreenCentered)
AddKeyboardShortcut(#WindowMain, #PB_Shortcut_Control | #PB_Shortcut_N, #EventMainKeyboardCtrlN)
AddKeyboardShortcut(#WindowMain, #PB_Shortcut_Control | #PB_Shortcut_O, #EventMainKeyboardCtrlO)
AddKeyboardShortcut(#WindowMain, #PB_Shortcut_Control | #PB_Shortcut_Q, #EventMainKeyboardCtrlQ)
AddKeyboardShortcut(#WindowMain, #PB_Shortcut_Escape, #EventMainKeyboardESC)
AddKeyboardShortcut(#WindowMain, #PB_Shortcut_F5, #EventMainKeyboardF5)
AddKeyboardShortcut(#WindowMain, #PB_Shortcut_Return, #EventNewKeyboardReturn)
AddKeyboardShortcut(#WindowMain1, #PB_Shortcut_Return, #EventNewSectionKeyboardReturn) ;The same key must be assigned to a different window.
Repeat
Select WaitWindowEvent()
Case #PB_Event_Menu
Select EventMenu()
Case #EventMainKeyboardCtrlN
Debug "#EventMainKeyboardCtrlN"
Case #EventMainKeyboardCtrlO
Debug "#EventMainKeyboardCtrlO"
Case #EventMainKeyboardCtrlQ
Debug "#EventMainKeyboardCtrlQ"
Case #EventMainKeyboardESC
Debug "#EventMainKeyboardESC"
Case #EventMainKeyboardF5
Debug "#EventMainKeyboardF5"
Case #EventNewKeyboardReturn
Debug "#EventNewKeyboardReturn"
Case #EventNewSectionKeyboardReturn
Debug "#EventNewSectionKeyboardReturn"
EndSelect
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndIf
Re: First custom event
Posted: Sat Mar 07, 2026 8:40 am
by coco2
I changed it to MenuItems and it seems to work now.
Maybe the Event enumeration was already used or something?
Re: First custom event
Posted: Sat Mar 07, 2026 8:54 am
by breeze4me
coco2 wrote: Sat Mar 07, 2026 8:40 am
Maybe the Event enumeration was already used ...?
Probably. Somewhere in the source code, including the .pbi files, there should be a line that says "Enumeration Events ...".
Another possibility is that while there is no "Enumeration Events" line, there may be values that duplicate existing menu item ID values.
For example, if the following constants are defined, the value of #EventNewSectionKeyboardReturn could become identical to #MenuItem6 or #MenuItem_6, potentially causing malfunction.
Code: Select all
#MenuItem6 = 6
#MenuItem7 = 16
#MenuItem8 = 26
; ...
; or
Enumeration MenuItems 6
#MenuItem_6
#MenuItem_7
#MenuItem_8
; ...
EndEnumeration
Enumeration Events
#EventMainKeyboardCtrlN
#EventMainKeyboardCtrlO
#EventMainKeyboardCtrlQ
#EventMainKeyboardESC
#EventMainKeyboardF5
#EventNewKeyboardReturn
#EventNewSectionKeyboardReturn ;= 10
EndEnumeration
Debug #EventNewSectionKeyboardReturn ; = 6
Re: First custom event
Posted: Sat Mar 07, 2026 9:40 pm
by Olli
I suggest you to identify the menu item otherwise.
file menu : 100
edit menu : 200
help menu : 300
file new : 110
file open : 120
file save : 130
file pref : 170
file quit : 190
file pref directories : 171
file pref colors : 172
edit undo : 210
edit redo : 220
edit cut : 230
edit copy : 240
edit paste : 250
help index : 310
help glossary : 320
help about : 390
help about authors : 391
help about licences : 392
etc... You can also use hexadecimal codes ($100, $101, etc...Maximum value = $FA00), and you can also use 4 digits (1000, 2000, 3000, etc...)
Custom example : editable combo box
Re: First custom event
Posted: Mon Mar 09, 2026 7:47 pm
by Piero
Custom events (Enumeration CustomEvents #PB_Event_FirstCustomValue) are for when you use
PostEvent
Re: First custom event
Posted: Mon Mar 09, 2026 8:03 pm
by coco2
Thanks for clearing it up. I'm trying to read the PureBasic help and I couldn't figure out what it meant
Re: First custom event
Posted: Tue Mar 10, 2026 1:05 am
by Piero
coco2 wrote: Mon Mar 09, 2026 8:03 pm I'm trying to read the PureBasic help and I couldn't figure out what it meant
…but never forget the
PDF help…
How to Install the PureBasic Search Bookmarklet
Create a new Bookmark in your browser’s Bookmarks Bar
Right-click it on Bookmarks Bar and edit the details:
Name: Search PB
URL/Location: Copy and paste the code below entirely:
Code: Select all
javascript:(function(){
var selected = document.getSelection().toString().trim();
if (selected === "") {
selected = prompt("No text selected.\nWhat would you like to search for on PureBasic sites?", "");
}
if (selected !== null && selected !== "") {
window.open('https://www.google.com/search?q=site:purebasic.fr OR site:purebasic.com/documentation ' + encodeURIComponent(selected));
}
})();
How to Use It
Highlight (select) any command or keyword(s) (like
PB_Event_FirstCustomValue or
thread mk-soft) on any webpage.
Click the
Search PB bookmark in your toolbar; a new tab will open with Google results restricted to the PureBasic forums and official documentation.
Note: If you don’t highlight anything, a pop-up box will appear asking you to type your search term(s) manually.
Re: First custom event
Posted: Tue Mar 10, 2026 8:43 am
by Olli

off topic
piero
Explanation of the first problem of this subject :
Understand the difference between a variable and a meta-variable.
A
variable is mainly managed by the
coder.
A
meta-variable is mainly managed by the
compiler.
This means that the compilation will ever fail, and your program will never work, if you want to know and display the real value of a
meta-variable in a specific line of your source code.
But a
meta-variable could be imaginated as a
variable.
Example code :
Here below, you have
iteration1 which is a
variable name.
And you have
iteration2 which is a
meta-variable name.
Here we go !
Code: Select all
Enumeration iteration2 100 Step 100
#var1
#var2
EndEnumeration
For iteration1 = 10 To 40 Step 10
Debug iteration1
Next
Enumeration iteration2
#var3
#var4
EndEnumeration
Debug #var1
Debug #var2
Debug #var3
Debug #var4
Remark : you can observe that, in this source code, I display manually four constants which are defined automacally.
That is the goal of a meta-variable : define
automatically any values of constants.
Re: First custom event
Posted: Tue Mar 10, 2026 1:00 pm
by Piero
Olli wrote: Tue Mar 10, 2026 8:43 amA
meta-variable is mainly managed by the
compiler.
Piero back on topic:
This one is a good example of using a "meta-variable" to avoid enumerations conflict, also if they are in multiple files
Re: First custom event
Posted: Tue Mar 10, 2026 6:52 pm
by Olli
Please let him have the time to learn. I put the link again here about
a simple custom event.