//key2code.hsp, v1.00 2011/03/05
//coded by 少女遊霊姫
#packopt runtime "hsp3c.hrt"
#packopt name "key2code"
#include "gdi32.as"
#packopt hide 1
#define ctype HIWORD(%1) (%1>>16&$FFFF)
#define ctype LOWORD(%1) (%1&$FFFF)
#define ctype HIBYTE(%1) (%1>>8&0xFF)
#define ctype LOBYTE(%1) (%1&0xFF)
#define WM_ACTIVATE $06
#define WM_SETFONT $30
#define WM_COMMAND $111
#define HKM_GETHOTKEY $0402

	screen 0,130,80,6
	title "key2code"
	oncmd gosub *WmCommand,WM_COMMAND
	onkey gosub *_OnKey
	pos 10,10
	winobj "msctls_hotkey32","",0,0x50000000,110,24
	hInput=objinfo(stat,2)
	idInput=stat
	GetStockObject 17
	sendmsg hInput,WM_SETFONT,stat
	gsel 0,2
	stop

*_OnKey
	objsel idInput
return

*WmCommand
	if lparam=hInput{
		if HIWORD(wparam)=$300{
			sendmsg hInput,HKM_GETHOTKEY,0,0:HotKey=stat
			color 255,255,255
			boxf
			color
			font "",12
			if HotKey!=0{
				pos 13,40
				mes "dec: "+HotKey
				pos 13,55
				mes "hex: 0x"+strf("%02X",HotKey)
				pos 80,40
				mes "mod: "+HIBYTE(HotKey)
				pos 80,55
				mes "key: "+LOBYTE(HotKey)
			}
		}
	}
return
