KEYNAME = {
	[1] = "MB_L",
	[2] = "MB_R",
	[4] = "MB_C",
	[8] = "Back",
	[9] = "Tab",
	[12] = "Clear",
	[13] = "Return",
	[16] = "Shift",
	[17] = "Ctrl",
	[18] = "Alt",
	[19] = "Pause",
	[20] = "Caps",
	[21] = "Hangul",
	[25] = "Hanja",
	[32] = "Space",
	[33] = "Prior",
	[34] = "Next",
	[35] = "End",
	[36] = "Home",
	[37] = "Left",
	[38] = "Up",
	[39] = "Right",
	[40] = "Down",
	[41] = "Select",
	[43] = "Execute",
	[44] = "Snapshot",
	[45] = "Ins",
	[46] = "Del",
	[47] = "Help",
	[48] = "0",
	[49] = "1",
	[50] = "2",
	[51] = "3",
	[52] = "4",
	[53] = "5",
	[54] = "6",
	[55] = "7",
	[56] = "8",
	[57] = "9",
	[65] = "A",
	[66] = "B",
	[67] = "C",
	[68] = "D",
	[69] = "E",
	[70] = "F",
	[71] = "G",
	[72] = "H",
	[73] = "I",
	[74] = "J",
	[75] = "K",
	[76] = "L",
	[77] = "M",
	[78] = "N",
	[79] = "O",
	[80] = "P",
	[81] = "Q",
	[82] = "R",
	[83] = "S",
	[84] = "T",
	[85] = "U",
	[86] = "V",
	[87] = "W",
	[88] = "X",
	[89] = "Y",
	[90] = "Z",
	[93] = "Apps",
	[96] = "Num_0",
	[97] = "Num_1",
	[98] = "Num_2",
	[99] = "Num_3",
	[100] = "Num_4",
	[101] = "Num_5",
	[102] = "Num_6",
	[103] = "Num_7",
	[104] = "Num_8",
	[105] = "Num_9",
	[106] = "Multiply",
	[107] = "Add",
	[108] = "Sep",
	[109] = "Sub",
	[110] = "Decimal",
	[111] = "Devide",
	[112] = "F1",
	[113] = "F2",
	[114] = "F3",
	[115] = "F4",
	[116] = "F5",
	[117] = "F6",
	[118] = "F7",
	[119] = "F8",
	[120] = "F9",
	[121] = "F10",
	[122] = "F11",
	[123] = "F12",
	[124] = "F13",
	[125] = "F14",
	[126] = "F15",
	[127] = "F16",
	[128] = "F17",
	[129] = "F18",
	[130] = "F19",
	[131] = "F20",
	[132] = "F21",
	[133] = "F22",
	[134] = "F23",
	[135] = "F24",
	[144] = "Num",
	[145] = "Scroll",
	[186] = ";",
	[187] = "=",
	[188] = ",",
	[189] = "-",
	[190] = ".",
	[191] = "/",
	[192] = "`",
	[219] = "[",
	[220] = "\\",
	[221] = "]",
	[222] = "'",
}
HOTKEY_1 = {
	[0] = { EXE = MsgStrID.MSI_HK_SKILLBAR1_1, KEY1 = 112 },
	[1] = { EXE = MsgStrID.MSI_HK_SKILLBAR1_2, KEY1 = 113 },
	[2] = { EXE = MsgStrID.MSI_HK_SKILLBAR1_3, KEY1 = 114 },
	[3] = { EXE = MsgStrID.MSI_HK_SKILLBAR1_4, KEY1 = 115 },
	[4] = { EXE = MsgStrID.MSI_HK_SKILLBAR1_5, KEY1 = 116 },
	[5] = { EXE = MsgStrID.MSI_HK_SKILLBAR1_6, KEY1 = 117 },
	[6] = { EXE = MsgStrID.MSI_HK_SKILLBAR1_7, KEY1 = 118 },
	[7] = { EXE = MsgStrID.MSI_HK_SKILLBAR1_8, KEY1 = 119 },
	[8] = { EXE = MsgStrID.MSI_HK_SKILLBAR1_9, KEY1 = 120 },
	[9] = { EXE = MsgStrID.MSI_HK_SKILLBAR2_1 },
	[10] = { EXE = MsgStrID.MSI_HK_SKILLBAR2_2 },
	[11] = { EXE = MsgStrID.MSI_HK_SKILLBAR2_3 },
	[12] = { EXE = MsgStrID.MSI_HK_SKILLBAR2_4 },
	[13] = { EXE = MsgStrID.MSI_HK_SKILLBAR2_5 },
	[14] = { EXE = MsgStrID.MSI_HK_SKILLBAR2_6 },
	[15] = { EXE = MsgStrID.MSI_HK_SKILLBAR2_7 },
	[16] = { EXE = MsgStrID.MSI_HK_SKILLBAR2_8 },
	[17] = { EXE = MsgStrID.MSI_HK_SKILLBAR2_9 },
	[18] = { EXE = MsgStrID.MSI_HK_SKILLBAR3_1 },
	[19] = { EXE = MsgStrID.MSI_HK_SKILLBAR3_2 },
	[20] = { EXE = MsgStrID.MSI_HK_SKILLBAR3_3 },
	[21] = { EXE = MsgStrID.MSI_HK_SKILLBAR3_4 },
	[22] = { EXE = MsgStrID.MSI_HK_SKILLBAR3_5 },
	[23] = { EXE = MsgStrID.MSI_HK_SKILLBAR3_6 },
	[24] = { EXE = MsgStrID.MSI_HK_SKILLBAR3_7 },
	[25] = { EXE = MsgStrID.MSI_HK_SKILLBAR3_8 },
	[26] = { EXE = MsgStrID.MSI_HK_SKILLBAR3_9 },
	[27] = { EXE = MsgStrID.MSI_HK_SKILLBAR4_1 },
	[28] = { EXE = MsgStrID.MSI_HK_SKILLBAR4_2 },
	[29] = { EXE = MsgStrID.MSI_HK_SKILLBAR4_3 },
	[30] = { EXE = MsgStrID.MSI_HK_SKILLBAR4_4 },
	[31] = { EXE = MsgStrID.MSI_HK_SKILLBAR4_5 },
	[32] = { EXE = MsgStrID.MSI_HK_SKILLBAR4_6 },
	[33] = { EXE = MsgStrID.MSI_HK_SKILLBAR4_7 },
	[34] = { EXE = MsgStrID.MSI_HK_SKILLBAR4_8 },
	[35] = { EXE = MsgStrID.MSI_HK_SKILLBAR4_9 }
}
HOTKEY_2 = {
	[0] = { EXE = MsgStrID.MSI_HK_BASICINFOWND_MINI, KEY1 = 86, KEY2 = 18 },
	[1] = { EXE = MsgStrID.MSI_HK_EQUIPWND_ONOFF, KEY1 = 81, KEY2 = 18 },
	[2] = { EXE = MsgStrID.MSI_HK_SKILLWND_ONOFF, KEY1 = 83, KEY2 = 18 },
	[3] = { EXE = MsgStrID.MSI_HK_QUESTWND_ONOFF, KEY1 = 85, KEY2 = 18 },
	[4] = { EXE = MsgStrID.MSI_HK_FRIENDWND_ONOFF, KEY1 = 72, KEY2 = 18 },
	[5] = { EXE = MsgStrID.MSI_HK_PARTYWND_ONOFF, KEY1 = 90, KEY2 = 18 },
	[6] = { EXE = MsgStrID.MSI_HK_CHATWND_MAKE, KEY1 = 67, KEY2 = 18 },
	[7] = { EXE = MsgStrID.MSI_HK_CARTWND_ONOFF, KEY1 = 87, KEY2 = 18 },
	[8] = { EXE = MsgStrID.MSI_HK_MAPWND_ONOFF, KEY1 = 192, KEY2 = 17 },
	[9] = { EXE = MsgStrID.MSI_HK_ITEMWND_ONOFF, KEY1 = 69, KEY2 = 18 },
	[10] = { EXE = MsgStrID.MSI_HK_GUILDWND_ONOFF, KEY1 = 71, KEY2 = 18 },
	[11] = { EXE = MsgStrID.MSI_HK_EMOTIONWND_ONOFF, KEY1 = 76, KEY2 = 18 },
	[12] = { EXE = MsgStrID.MSI_HK_SITORSTAND, KEY1 = 45 },
	[13] = { EXE = MsgStrID.MSI_HK_MINIMAP_ONOFF, KEY1 = 9, KEY2 = 17 },
	[14] = { EXE = MsgStrID.MSI_HK_MACROWND_ONOFF, KEY1 = 77, KEY2 = 18 },
	[15] = { EXE = MsgStrID.MSI_HK_EXEWND_ONOFF, KEY1 = 89, KEY2 = 18 },
	[16] = { EXE = MsgStrID.MSI_HK_ALLWND_OFF, KEY1 = 122 },
	[17] = { EXE = MsgStrID.MSI_HK_SKILLBAR_ONOFF, KEY1 = 123 },
	[18] = { EXE = MsgStrID.MSI_HK_CHATWND_ONOFF, KEY1 = 121, KEY2 = 18 },
	[19] = { EXE = MsgStrID.MSI_HK_CHATWND_ZOOM, KEY1 = 121 },
	[20] = { EXE = MsgStrID.MSI_HK_GAGE_ONOFF, KEY1 = 35, KEY2 = 18 },
	[21] = { EXE = MsgStrID.MSI_HK_SNAPSHOT, KEY1 = 44 },
	[22] = { EXE = MsgStrID.MSI_HK_MEMORIALWND_ONOFF, KEY1 = 66, KEY2 = 18 },
	[23] = { EXE = MsgStrID.MSI_HK_PETWND_ONOFF, KEY1 = 74, KEY2 = 18 },
	[24] = { EXE = MsgStrID.MSI_HK_HOMUNWND_ONOFF, KEY1 = 82, KEY2 = 18 },
	[25] = { EXE = MsgStrID.MSI_HK_MERWND_ONOFF, KEY1 = 82, KEY2 = 17 },
	[26] = { EXE = MsgStrID.MSI_HK_HOMUN_FOLLOW, KEY1 = 84, KEY2 = 18 },
	[27] = { EXE = MsgStrID.MSI_HK_MER_FOLLOW, KEY1 = 84, KEY2 = 17 },
	[28] = { EXE = MsgStrID.MSI_HK_FRIEND_OPTIONWND },
	[29] = { EXE = MsgStrID.MSI_HK_PARTY_OPTIONWND },
	[30] = { EXE = MsgStrID.MSI_HK_BATTLEFIELDWND },
	[31] = { EXE = MsgStrID.MSI_HK_CHATMODE_ONOFF, KEY1 = 13 },
	[32] = { EXE = MsgStrID.MSI_HK_BASICINFOWND_BTN_ONOFF, KEY1 = 192, KEY2 = 18 },
	[33] = { EXE = MsgStrID.MSI_HK_PARTY_RECRUIT },
	[34] = { EXE = MsgStrID.MSI_HK_PARTY_BOOKING_LIST },
	[35] = { EXE = MsgStrID.MSI_HK_GROUND_CURSOR_ONOFF, KEY1 = 36, KEY2 = 18 },
	[36] = { EXE = MsgStrID.MSI_HK_EXMACRO_SETUPWND },
	[37] = { EXE = MsgStrID.MSI_HK_CASHSHOPWND }
}
HOTKEY_3 = {
	[0] = { EXE = MsgStrID.MSI_HK_MACRO_1, KEY1 = 49, KEY2 = 18 },
	[1] = { EXE = MsgStrID.MSI_HK_MACRO_2, KEY1 = 50, KEY2 = 18 },
	[2] = { EXE = MsgStrID.MSI_HK_MACRO_3, KEY1 = 51, KEY2 = 18 },
	[3] = { EXE = MsgStrID.MSI_HK_MACRO_4, KEY1 = 52, KEY2 = 18 },
	[4] = { EXE = MsgStrID.MSI_HK_MACRO_5, KEY1 = 53, KEY2 = 18 },
	[5] = { EXE = MsgStrID.MSI_HK_MACRO_6, KEY1 = 54, KEY2 = 18 },
	[6] = { EXE = MsgStrID.MSI_HK_MACRO_7, KEY1 = 55, KEY2 = 18 },
	[7] = { EXE = MsgStrID.MSI_HK_MACRO_8, KEY1 = 56, KEY2 = 18 },
	[8] = { EXE = MsgStrID.MSI_HK_MACRO_9, KEY1 = 57, KEY2 = 18 },
	[9] = { EXE = MsgStrID.MSI_HK_MACRO_10, KEY1 = 48, KEY2 = 18 },
	[10] = { EXE = MsgStrID.MSI_HK_FLAG_1, KEY1 = 49, KEY2 = 17 },
	[11] = { EXE = MsgStrID.MSI_HK_FLAG_2, KEY1 = 50, KEY2 = 17 },
	[12] = { EXE = MsgStrID.MSI_HK_FLAG_3, KEY1 = 51, KEY2 = 17 },
	[13] = { EXE = MsgStrID.MSI_HK_FLAG_4, KEY1 = 52, KEY2 = 17 },
	[14] = { EXE = MsgStrID.MSI_HK_FLAG_5, KEY1 = 53, KEY2 = 17 },
	[15] = { EXE = MsgStrID.MSI_HK_FLAG_6, KEY1 = 54, KEY2 = 17 },
	[16] = { EXE = MsgStrID.MSI_HK_FLAG_7, KEY1 = 55, KEY2 = 17 },
	[17] = { EXE = MsgStrID.MSI_HK_FLAG_8, KEY1 = 56, KEY2 = 17 },
	[18] = { EXE = MsgStrID.MSI_HK_FLAG_9, KEY1 = 57, KEY2 = 17 },
	[19] = { EXE = MsgStrID.MSI_HK_FLAG_10, KEY1 = 48, KEY2 = 17 }

}
BEHAVIOR_TO_WINDOWID = {
	[0] = 0,
	[10] = 1,
	[37] = 2,
	[134] = 3,
	[40] = 7,
	[140] = 8,
	[8]= 9,
	[59] = 10,
	[87] = 11,
	[86] = 14,
	[112] = 15,
	[36] = 17,
	[137] = 22,
	[88] = 23,
	[113] = 24,
	[125] = 25,
	[157] = 30,
	[191] = 36,
	[184] = 37,
}

--Function #0
GetKeyDes = function(key1, key2)
	local keyName1 = KEYNAME[key1]
	local keyName2 = KEYNAME[key2]
	if keyName1 == nil then
		return ""
	elseif keyName2 ~= nil then
		return string.format("%s + %s", keyName2, keyName1)
	else
		return keyName1
	end
end

--Function #1
GetBeHaviorOfWindow = function(winID)
	local behavior = BEHAVIOR_TO_WINDOWID[winID]
	if behavior ~= nil then
			local userTable = USERKEY_2
			local key1 = nil
			local key2 = nil
		if userTable ~= nil then
			userTable = USERKEY_2[behavior]
			if userTable ~= nil and userTable ~= "NULL" then
				key1 = userTable["KEY1"]
				key2 = userTable["KEY2"]
			end
		end
		if key1 == nil then
			key1 = HOTKEY_2[behavior]["KEY1"]
			key2 = HOTKEY_2[behavior]["KEY2"]
		end
		if key1 ~= nil then
			return GetKeyDes(key1, key2)
		else
			return ""
		end
	else
		return ""
	end
end

--Function #2
GetHotKeyInfo = function(tableName, idx)
	element = _G[tableName]
	if element ~= nil then
		v = element[idx]
		if v == nil or v == "NULL" then
			return 0,0,toStr(""),toStr("")
		else
			return toInt(v["KEY1"]), toInt(v["KEY2"]), toStr(GetKeyDes(v["KEY1"],v["KEY2"])), toStr(v["EXE"])
		end
	else
		return 0,0,toStr(""),toStr("")
	end
end

--Function #3
GetOriginalHotKeyInfo = function(tabNum, idx)
	return GetHotKeyInfo(string.format("HOTKEY_%d", tabNum), idx)
end

--Function #4
GetUserHotKeyInfo = function(tabNum, idx)
	return GetHotKeyInfo(string.format("USERKEY_%d", tabNum), idx)
end

--Function #5
GetOriginalHotKeyListSize = function(tabNum)
	local tableSize = 0
	table = _G[string.format("HOTKEY_%d", tabNum)]
	if table ~= nil then
		tableSize = getTableSize(_G[string.format("HOTKEY_%d", tabNum)])
	end
	return tableSize
end

--Function #6
GetHotKey = function(tabNum, idx)
	key1,key2,des,exe = GetUserHotKeyInfo(tabNum, idx)
	if exe == "" then
		return GetOriginalHotKeyInfo(tabNum, idx)
	end
	return key1,key2,des,exe
end

--Function #7
GetBehaviorOfHotKey = function(inKey1, inKey2)
	size = 0
	tab = 1
	tableLen = GetOriginalHotKeyListSize(tab)
	while tableLen ~= 0 do
		idx = 0
		key1,key2,des,exe = GetHotKey(tab, idx)
		while exe ~= "" do
			if exe == MsgStrID.MSI_HK_CHATMODE_ONOFF and key1 == inKey1 then
				return idx + ((tab - 1) * 100)
			end
			if key1 == inKey1 and key2 == inKey2 then
				return idx + ((tab - 1) * 100)
			end
		idx = idx + 1
		key1,key2,des,exe = GetHotKey(tab, idx)
		end
	size = size + tableLen
	tab = tab + 1
	tableLen = GetOriginalHotKeyListSize(tab)
	end
	return -1
end

--Function #8
ChangeUserHotKey = function(tabNum, idx, exe, key1, key2)
	TableName = string.format("USERKEY_%d", tabNum)
	UserKeyTable = _G[TableName]
	originalKey1,originalKey2,dis,exe = GetOriginalHotKeyInfo(tabNum, idx)
	if string.len(exe) ~= 0 and key1 == originalKey1 and key2 == originalKey2 and UserKeyTable ~= nil then
		UserKeyTable[idx] = nil
		return
	end
	if UserKeyTable == nil then
		UserKeyTable = {}
	end
	UserKey = UserKeyTable[idx]
	if UserKey == "NULL" then
		UserKey = nil
	end
	if UserKey == nil then
		UserKey = {}
	end
	UserKey["EXE"] = exe
	UserKey["KEY1"] = key1
	UserKey["KEY2"] = key2
	UserKeyTable[idx] = UserKey
	_G[TableName] = UserKeyTable
end

--Function #9
GetIndexOfTheUserHotKey = function(inKey1, inKey2)
	tab = 1
	tableLen = GetOriginalHotKeyListSize(tab)
	while tableLen ~= 0 do
		idx = 0
		key1,key2,des,exe = GetUserHotKeyInfo(tab, idx)
			while idx < tableLen do
				if key1 == inKey1 and key2 == inKey2 then
					return idx
				end
			idx = idx + 1
			key1,key2,des,exe = GetUserHotKeyInfo(tab, idx)
			end
		tab = tab + 1
		tableLen = GetOriginalHotKeyListSize(tab)
	end
	return -1
end

--Function #10
ResetTheHotKey  = function(tabNum, idx, inKey1, inKey2)
	tableLen = GetOriginalHotKeyListSize(tabNum)
	idx = idx - tableLen
	tabNum = tabNum + 1
	TableName = string.format("USERKEY_%d", tabNum)
	UserKeyTable = _G[TableName]
	if UserKeyTable == nil then
		return
	end
	key1,key2,des,exe = GetUserHotKeyInfo(tabNum, idx)
	if key1 == 0 and key2 == 0 then
		idx2 = GetIndexOfTheUserHotKey(inKey1, inKey2)
		if idx2 ~= -1 then
			UserKeyTable[idx2] = nil
		end
	end
end

--Function #11
SaveUserHotKeys = function(saveFileName)
	saveFile = io.open(saveFileName,"w")
	if saveFile ~= nil then
		tabNum = 1
		while tabNum <= 3 do
			userTable = _G[string.format("USERKEY_%d", tabNum)]
			if userTable ~= nil then
				saveFile:write(string.format("USERKEY_%d = {\n", tabNum))
				idx = 0
				key1,key2,keyDes,behaviorDes = GetUserHotKeyInfo(tabNum, idx)
				tableLen = GetOriginalHotKeyListSize(tabNum)
				while idx < tableLen do
					if behaviorDes ~= "" then
						saveFile:write(string.format("\t[%d] = { EXE = \"%s\"", idx, behaviorDes))
						if key1 ~= 0 then
							saveFile:write(string.format(", KEY1 = %d", key1))
						end
						if key2 ~= 0 then
							saveFile:write(string.format(", KEY2 = %d", key2))
						end
						saveFile:write(" },\n")
					end
				idx = idx + 1
				key1,key2,keyDes,behaviorDes = GetUserHotKeyInfo(tabNum, idx)
				end
			saveFile:write("}\n\n")
			end
		tabNum = tabNum + 1
		end
	end
	io.close(saveFile)
end