Skip to content

Instantly share code, notes, and snippets.

@perfaram perfaram/Serial_input.au3
Last active Aug 29, 2015

Embed
What would you like to do?
(AutoIT) Creating licence key input box
#include <GUIConstantsEx.au3>
HotKeySet("{BACKSPACE}","_BackSpace")
Global $gui = GUICreate("...",600)
Global $Input = GUICtrlCreateInput("", 8, 150, 584, 35)
GUICtrlSetLimit($Input,29)
GUICtrlSetFont($Input,20)
Global $LastInput = ""
GUISetState()
Local $Temp, $LenPart = 5
While 1
If $LastInput <> GUICtrlRead($Input) Then
$LastInput = GUICtrlRead($Input)
If StringLen($LastInput) = $LenPart Then
$LastInput &= "-"
Else
$Temp = StringSplit($LastInput,"-")
If $Temp[$Temp[0]] <> "" And StringLen($Temp[$Temp[0]]) >= $LenPart And StringLen(GUICtrlRead($Input)) < 29 Then
$LastInput &= "-"
EndIf
EndIf
GUICtrlSetData($Input,$LastInput)
EndIf
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _BackSpace()
If Not WinActive($gui) Then Return 0
If StringRight($LastInput,1) = "-" Then
Return GUICtrlSetData($Input,StringLeft($LastInput,StringLen($LastInput)-2))
Else
Return GUICtrlSetData($Input,StringLeft($LastInput,StringLen($LastInput)-1))
EndIf
EndFunc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.