#include once "window9.bi"

ReDim Shared StructA__ACC(0) As ACCELERATORSTRUCT

Function AddKeyboardShortcut(ByVal hwnd As HWND,ByVal Syskey As Integer,ByVal Shortcut As integer, ByVal ID_Event As Integer) As HACCEL Export
	Dim As Integer UBOUND_=UBound(StructA__ACC)
	For a As Integer=0 To UBOUND_
		If StructA__ACC(a).hwnd=hwnd Then
			Dim As integer NACC=CopyAcceleratorTable(StructA__ACC(a).hAccel,0,0)
			Dim As ACCEL  AcceleratorRES(NACC+1)
			CopyAcceleratorTable(StructA__ACC(a).hAccel,@AcceleratorRes(0),NACC)
			DestroyAcceleratorTable(StructA__ACC(a).hAccel)
			For b As Integer=0 To NACC
				If AcceleratorRes(b).cmd=ID_Event Then
					AcceleratorRes(b).key=Shortcut
					AcceleratorRes(b).fVirt=FVIRTKEY Or Syskey
					StructA__ACC(a).hAccel=CreateAcceleratorTable(cast(LPACCEL,@AcceleratorRes(0)),NACC)
					win9GetAcceleratorInfo(@StructA__ACC(a))
					Return StructA__ACC(a).hAccel
				EndIf
			Next
			AcceleratorRes(NACC).cmd=ID_Event
			AcceleratorRes(NACC).key=Shortcut
			AcceleratorRes(NACC).fVirt=FVIRTKEY Or Syskey
			StructA__ACC(a).hAccel=CreateAcceleratorTable(cast(LPACCEL,@AcceleratorRes(0)),NACC+1)
			win9GetAcceleratorInfo(@StructA__ACC(a))
			Return StructA__ACC(a).hAccel
		EndIf
	Next
	If StructA__ACC(UBOUND_).hwnd<>0 Then
		UBOUND_+=1
		ReDim Preserve StructA__ACC(UBOUND_) As ACCELERATORSTRUCT
	EndIf
	Dim As ACCEL  Accelerator(1)
	Accelerator(0).cmd = ID_Event
	Accelerator(0).fVirt = FVIRTKEY Or Syskey
	Accelerator(0).key = Shortcut
	StructA__ACC(UBOUND_).hwnd=hwnd
	StructA__ACC(UBOUND_).hAccel=CreateAcceleratorTable(cast(LPACCEL,@Accelerator(0)),1)
	win9GetAcceleratorInfo(@StructA__ACC(UBOUND_))
	
	Return StructA__ACC(UBOUND_).hAccel
	
End Function

Sub DeleteAllKeyboardShortcut(ByVal hwnd As HWND) Export
	Dim As Integer a=UBound(StructA__ACC)
	For b As Integer=0 To a
		If StructA__ACC(b).hwnd=hwnd Then
			DestroyAcceleratorTable(StructA__ACC(b).hAccel)
			StructA__ACC(b).hAccel=0
			win9GetAcceleratorInfo(@StructA__ACC(b))
			StructA__ACC(b).hwnd=0
		EndIf
	Next
End Sub
