Restored from previous forum. Originally posted by Fangbeast.
If I define an up and downarrow keyboard shortcut, can I limit the detection to sepcific gadgets? (Since keyboardshortcuts are eventmenuid() events)
AddKeyboardShortcut(0, #PB_Shortcut_Up, 500) ; make the shortcuts
AddKeyboardShortcut(0, #PB_Shortcut_Down, 501)
; events section -------------------------------------------------
If EventID = #PB_EventGadget
Select EventGadgetID()
Case #CategoryTree ; This is my Tree Gadget
If EventMenuID() = 500
; Do some stuff
EndIF
EndSelect
EndIf
;-----------------------------------------------------------------
Can events be mixed like this to localise detection of these sorts of keyboardshortucts to specific gadgets?
Fangles
Keyboardshortcut detection to a specific gadget
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
This willn't run as a ShotCut returns a menu event, so EventID = #PB_Event_Menu.
You have to do:
If EventID = #PB_Event_Gadget
....
ElseIf EventID = #PB_Event_Menu ; Menu shortcut
If EventMenuID() = 500 ; You got it !
EndIf
EndIf
Fred - AlphaSND
This willn't run as a ShotCut returns a menu event, so EventID = #PB_Event_Menu.
You have to do:
If EventID = #PB_Event_Gadget
....
ElseIf EventID = #PB_Event_Menu ; Menu shortcut
If EventMenuID() = 500 ; You got it !
EndIf
EndIf
Fred - AlphaSND
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Fangbeast.
So, how do I do that?
Fangles
I understand that but I want to detect specifically if Up/down was pressed in TreeGadget or Up/Down was pressed specifically in ListIconGadget.This willn't run as a ShotCut returns a menu event, so EventID = #PB_Event_Menu.
You have to do:
If EventID = #PB_Event_Gadget
....
ElseIf EventID = #PB_Event_Menu ; Menu shortcut
If EventMenuID() = 500 ; You got it !
EndIf
EndIf
Fred - AlphaSND
So, how do I do that?
Fangles
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Danilo.
Try this...
cya,
...Danilo
(registered PureBasic user)
Code: Select all
If EventMenuID() = 500 ; You got it !
x = GetFocus_()
Select x
Case hTreeView ; Handle of TreeView
; [...]
Case hListView ; Handle of Listview
; [...]
EndSelect
EndIfcya,
...Danilo
(registered PureBasic user)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Fangbeast.
Thanks a lot once again
Fangles
Thanks Danilo, that was a great lesson in thinking laterally and will come in useful for other newbies like myself (grin). I've adapted your code like this and it works wonderfully well. Thanks again.Try this...Code: Select all
If EventMenuID() = 500 ; You got it ! x = GetFocus_() Select x Case hTreeView ; Handle of TreeView ; [...] Case hListView ; Handle of Listview ; [...] EndSelect EndIf
cya,
...Danilo
(registered PureBasic user)
Code: Select all
If EventID = #PB_EventMenu
Select EventMenuID()
Case #F1Code
Gosub Help_Wanted
Case #F2Code
Gosub Find_First
Case #F3Code
If First_Match 0
Gosub Find_Next
EndIf
Case #DelCode
Gosub Delete_Record
Case #UpCode
If GetFocus_() And TreeBox
SetGadgetState(#CategoryTree, GetGadgetState(#CategoryTree) - 1)
Gosub Display_Categories
EndIf
Case #DownCode
If GetFocus_() And TreeBox (TreeBox is my TreeGadget handle)
SetGadgetState(#CategoryTree, GetGadgetState(#CategoryTree) + 1)
Gosub Display_Categories
EndIf
EndSelect
EndIf
Fangles
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Fangbeast.
Fangles
I usually do but decided not to change the way I did all my code for now. I had all the handles in place for API calls that I am slowly replacing with PB code for portability to Unix. Not many to go thank goodness.Just use GadgetID() to get the handle of the Gadget easely..
Fred - AlphaSND
Fangles