#include-once #include #include ; https://github.com/ez2sugul/stopwatch_client/blob/master/JSMN.au3 #include Global $iDel = 0 OnAutoItExitRegister("_EXIT_BEFORE") Opt("GUIOnEventMode", 1) ;~ Opt("GUIEventOptions", 1) Opt("MustDeclareVars", 1) Global $INI = "file.ini" Global $SEND = "local_server_input" Global Const $SD = "Scripting.Dictionary" Global $aGuiSize[2] = [300, 366] Global $sGuiTitle = "GuiTitle" Global $hGui Global $oDel = ObjCreate($SD) Global $aSize[5] = [14, 10, 6, 6, 64] Global $aKeys[18][7] = [ _ [0, 0, 0, $aSize[4], $aSize[4], "Num Lock", 1], _ [0, 0, 1, $aSize[4], $aSize[4], "7", 1], _ [0, 0, 2, $aSize[4], $aSize[4], "4", 1], _ [0, 0, 3, $aSize[4], $aSize[4], "1", 1], _ [0, 0, 4, $aSize[4] * 2, $aSize[4], "0", 1], _ [0, 1, 0, $aSize[4], $aSize[4], "/", 1], _ [0, 1, 1, $aSize[4], $aSize[4], "8", 1], _ [0, 1, 2, $aSize[4], $aSize[4], "5", 1], _ [0, 1, 3, $aSize[4], $aSize[4], "2", 1], _ [0, 2, 0, $aSize[4], $aSize[4], "*", 1], _ [0, 2, 1, $aSize[4], $aSize[4], "9", 1], _ [0, 2, 2, $aSize[4], $aSize[4], "6", 1], _ [0, 2, 3, $aSize[4], $aSize[4], "3", 1], _ [0, 2, 4, $aSize[4], $aSize[4], ",", 1], _ [0, 3, 0, $aSize[4], $aSize[4], "-", 1], _ [0, 3, 1, $aSize[4], $aSize[4], "+", 1], _ [0, 3, 2, $aSize[4], $aSize[4], ".", 1], _ [0, 3, 3, $aSize[4], $aSize[4] * 2, "ENTER", 1] _ ] $hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1]) GUISetOnEvent($GUI_EVENT_CLOSE, "_EXIT") For $ii = 0 To UBound($aKeys, 1) - 1 $aKeys[$ii][0] = GUICtrlCreateButton($aKeys[$ii][5], $aSize[0] + $aKeys[$ii][1] * ($aSize[2] + $aSize[4]), $aSize[1] + $aKeys[$ii][2] * ($aSize[3] + $aSize[4]), $aKeys[$ii][3] + ($aKeys[$ii][3] == $aSize[4] ? 0 : $aSize[2]), $aKeys[$ii][4] + ($aKeys[$ii][4] == $aSize[4] ? 1 : $aSize[3]), 0x1000) GUICtrlSetOnEvent($aKeys[$ii][0], "press_key") Next GUISetState(@SW_SHOW, $hGui) AdlibRegister("read_ini", 50) AdlibRegister("clear", 10) While Sleep(100) WEnd Func read_ini() Local $json = IniRead($INI, @UserName, "received", "") If $json Then IniWrite($INI, @UserName, "received", "") $json = BinaryToString($json, 4) $json = Jsmn_Decode($json) add_clear($json.Item("key"), $json.Item("time"), $json.Item("color")) EndIf EndFunc ;==>read_ini Func add_clear($key, $time, $color) GUICtrlSetBkColor($key, $color) GUICtrlSetState($key, $GUI_DISABLE) $iDel += 1 $oDel.Add($iDel, ObjCreate($SD)) $oDel.Item($iDel).Add("key", $key) $oDel.Item($iDel).Add("time", $time) $oDel.Item($iDel).Add("start", TimerInit()) EndFunc ;==>add_clear Func clear() Local $oo = ObjCreate($SD) If $oDel.Count Then For $each In $oDel If TimerDiff($oDel.Item($each).Item("start")) > $oDel.Item($each).Item("time") Then GUICtrlSetBkColor($oDel.Item($each).Item("key"), 0xD4D0C8) GUICtrlSetState($oDel.Item($each).Item("key"), BitOR($GUI_ENABLE, $GUI_FOCUS)) $oo.Add($each, 0) EndIf Next EndIf If $oo.Count Then For $each In $oo $oDel.Remove($each) Next EndIf EndFunc ;==>clear Func _EXIT() MsgBox(0, "_EXIT", "_EXIT") Exit EndFunc ;==>_EXIT Func _EXIT_BEFORE($sInput = 0) AdlibUnRegister("clear") AdlibUnRegister("read_ini") ConsoleWrite("#Func _exit( $sInput=" & (IsDeclared("sInput") ? $sInput : "") & " )" & @LF) GUIDelete($hGui) EndFunc ;==>_EXIT_BEFORE Func press_key() Local $oo = ObjCreate($SD) $oo.Add("key", @GUI_CtrlId) Local $json = StringToBinary(Jsmn_Encode_Compact($oo), 4) IniWrite($INI, $SEND, @UserName, $json) EndFunc ;==>press_key