How to set the same hot key for only two gadgets

BlitzMax Forums/MaxGUI Module/How to set the same hot key for only two gadgets

Fabian.(Posted 2006) [#1]
It seems to be an easy question: I've three windows (gadgets) and I want to set the same hot key for two of them, but not for the third.
I tried to use SetGadgetHotKey, but setting the hot key for the second window overrides the existing hot key of the first window. So SetGadgetHotKey (in contrast to SetGadgetText/Shape/Font/...) doesn't set a gadget's property, it only sets a global thing associated with a gadget (Maybe a bug?)
I looked a the source code of SetGadgetHotKey and (on Win32) it simply calls SetHotKeyEvent with the owner parameter set to the gadget's window handle.
The source of the SetHotKeyEvent shows:
Function SetHotKeyEvent:THotKey( key,mods,event:TEvent=Null,owner=0 )
	If Not event event=CreateEvent( EVENT_HOTKEYHIT,Null,key,mods )
	Local t:THotKey=hotKeys
	While t
		If t.key=key And t.mods=mods Exit
		t=t.succ
	Wend
	If Not t
		t=New THotKey
		t.key=key
		t.mods=mods
		t.succ=hotKeys
		hotKeys=t
	EndIf
	t.event=event
	t.owner=owner
	Return t
End Function
The code searches for an existing hot key event with same key and mods and if something is found the event and the owner is updated.
This might be a bug. For now I found a workaround by simply changing the SetHotKeyEvent function to:
Function SetHotKeyEvent:THotKey( key,mods,event:TEvent=Null,owner=0 )
	If Not event event=CreateEvent( EVENT_HOTKEYHIT,Null,key,mods )
	Local t:THotKey=hotKeys
	While t
		If t.key=key And t.mods=mods And t.owner=owner Exit
		t=t.succ
	Wend
	If Not t
		t=New THotKey
		t.key=key
		t.mods=mods
		t.owner=owner
		t.succ=hotKeys
		hotKeys=t
	EndIf
	t.event=event
	Return t
End Function
It searches for a hot key with same key and mods and owner and then if found only updates the event.
This workaround works for my problem, but it is not the final solution, because I have to change the function after each call to syncmods.


Fabian.(Posted 2006) [#2]
First I planed to post it as bug report, but priviously I wanted to hear whether it's a really a bug or whether there's an easy other way to solve my problem.
And in between, it seems like the owner parameter in the SetHotKeyEvent function isn't documented; does anyone know a reason?