• Ich weiß, dass das nichts besonderes ist aber vielleicht kann ja irgendjemand etwas daraus verwenden. :)
    Ein PIN Pad mit Zeitlimit und einer Wartezeit für die Eingabe. Komplett in GDI+ gezeichnet ohne externe Grafiken.

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include <GUIConstants.au3>
    #include <GDIPlus.au3>
    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $GUIColorBG = 0xFFFFFFFF ;Hintergrundfarbe der GUI
    $PadColor = 0xFF000000 ;Farbe der Pads
    $PadTextColor = 0xFFFFFFFF ;Farbe des Textes auf den Pads
    $ColorActive = 0xFF00FF00 ;Farbe der Pads, wenn aktiviert
    $PadSize = 35 ;Größe der Pads
    $Space = 5 ;Distanz zwischen den Pads
    $GUIWidth = ($Space + $PadSize) * 3 + $Space ;GUI Breite (wird aus Padgröße berechnet)
    $GUIHeight = ($Space + $PadSize) * 4 + $Space ;GUI Höhe (wird aus Padgröße berechnet)

    [/autoit] [autoit][/autoit] [autoit]

    $Key = ""
    $Pass = "12345" ;Richtiges Passwort
    $Timelimit = 20000 ;Zeitlimit für die Eingabe (nach Ablauf schließt sich das Script ordnungsgemäß)

    [/autoit] [autoit][/autoit] [autoit]

    #Region Pad Koordinaten
    Dim $aPad[12][3]
    $aPad[0][0] = $Space
    $aPad[0][1] = $Space
    $aPad[0][2] = "1"
    $aPad[1][0] = $Space + $PadSize + $Space
    $aPad[1][1] = $Space
    $aPad[1][2] = "2"
    $aPad[2][0] = ($Space + $PadSize) * 2 + $Space
    $aPad[2][1] = $Space
    $aPad[2][2] = "3"
    $aPad[3][0] = $Space
    $aPad[3][1] = $Space + $PadSize + $Space
    $aPad[3][2] = "4"
    $aPad[4][0] = $Space + $PadSize + $Space
    $aPad[4][1] = $Space + $PadSize + $Space
    $aPad[4][2] = "5"
    $aPad[5][0] = ($Space + $PadSize) * 2 + $Space
    $aPad[5][1] = $Space + $PadSize + $Space
    $aPad[5][2] = "6"
    $aPad[6][0] = $Space
    $aPad[6][1] = ($Space + $PadSize) * 2 + $Space
    $aPad[6][2] = "7"
    $aPad[7][0] = $Space + $PadSize + $Space
    $aPad[7][1] = ($Space + $PadSize) * 2 + $Space
    $aPad[7][2] = "8"
    $aPad[8][0] = ($Space + $PadSize) * 2 + $Space
    $aPad[8][1] = ($Space + $PadSize) * 2 + $Space
    $aPad[8][2] = "9"
    $aPad[9][0] = $Space
    $aPad[9][1] = ($Space + $PadSize) * 3 + $Space
    $aPad[9][2] = "R"
    $aPad[10][0] = $Space + $PadSize + $Space
    $aPad[10][1] = ($Space + $PadSize) * 3 + $Space
    $aPad[10][2] = "0"
    $aPad[11][0] = ($Space + $PadSize) * 2 + $Space
    $aPad[11][1] = ($Space + $PadSize) * 3 + $Space
    $aPad[11][2] = "OK"
    #EndRegion Pad Koordinaten

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("PIN", $GUIWidth, $GUIHeight, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION))
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd) ;Erstellt eine Grafik aus der Clientfläche der GUI
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($GUIWidth, $GUIHeight, $hGraphic) ;Erstellt eine Bitmap aus der Grafik
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;Erstellt eine Grafik die der Bitmap zugeordnet ist
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2) ;Anti-Aliasing
    _GDIPlus_GraphicsClear($hGraphic, $GUIColorBG) ;Füllt eine Grafik komplett in einer Farbe

    [/autoit] [autoit][/autoit] [autoit]

    $Brush_Pad = _GDIPlus_BrushCreateSolid($PadColor) ;Erstellt ein Füllobjekt mit einer bestimmten Farbe
    $Brush_Pad_Active = _GDIPlus_BrushCreateSolid($ColorActive)
    $Brush_Number = _GDIPlus_BrushCreateSolid($PadTextColor)

    [/autoit] [autoit][/autoit] [autoit]

    #Region Schrift
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
    #EndRegion Schrift

    [/autoit] [autoit][/autoit] [autoit]

    _DrawPad()
    $Estimated_Time = TimerInit() ;Initialisiert das Zeitlimit

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg(1) ;Wenn Parameter auf 1 ist, dann wird ein Array mit zusätzlichen Infos zurückgegeben
    Switch $nMsg[0]
    Case $GUI_EVENT_CLOSE
    _Exit()
    Case $GUI_EVENT_PRIMARYDOWN
    For $i = 0 To UBound($aPad, 1) - 1
    If $nMsg[3] > $aPad[$i][0] And $nMsg[3] < $aPad[$i][0] + $PadSize And $nMsg[4] > $aPad[$i][1] And $nMsg[4] < $aPad[$i][1] + $PadSize Then _PadEvent($i) ;Überprüft, ob der Mausklick auf ein bestimmtes Pad erfolgt
    _DrawPad()
    Next
    EndSwitch
    If Not WinActive($hWnd) Then ;Wenn Fenster nicht aktiv, dann...
    While 1
    If WinActive($hWnd) Then ;Wenn Fenster wieder aktiv, dann... (Um zu verhindern, dass die GUI übermalt wird)
    _DrawPad()
    ExitLoop
    EndIf
    WEnd
    EndIf
    If TimerDiff($Estimated_Time) > $Timelimit Then ;Überprüft, ob das Zeitlimit erreicht ist
    _Exit()
    EndIf
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawPad()
    _GDIPlus_GraphicsClear($hBuffer, $GUIColorBG) ;Leert den Buffer
    For $i = 0 To UBound($aPad, 1) - 1
    _GDIPlus_GraphicsFillRect($hBuffer, $aPad[$i][0], $aPad[$i][1], $PadSize, $PadSize, $Brush_Pad) ;Zeichnet ein Pad
    $tLayout = _GDIPlus_RectFCreate($aPad[$i][0], $aPad[$i][1], $PadSize, $PadSize) ;Legt das Layout für den Schriftzug fest
    $aInfo = _GDIPlus_GraphicsMeasureString($hBuffer, $aPad[$i][2], $hFont, $tLayout, $hFormat) ;Passt das Layout auf die berechnete Größe für den String an
    _GDIPlus_GraphicsDrawStringEx($hBuffer, $aPad[$i][2], $hFont, $aInfo[0], $hFormat, $Brush_Number) ;Zeichnet den String auf das Pad
    Next
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $GUIWidth, $GUIHeight) ;Zeichnet den Buffer in die GUI Grafik
    EndFunc ;==>_DrawPad

    [/autoit] [autoit][/autoit] [autoit]

    Func _PadEvent($iPad)
    _GDIPlus_GraphicsFillRect($hBuffer, $aPad[$iPad][0], $aPad[$iPad][1], $PadSize, $PadSize, $Brush_Pad_Active) ;Macht das gleiche wie oben nur mit einer anderen Farbe
    $tLayout = _GDIPlus_RectFCreate($aPad[$iPad][0], $aPad[$iPad][1], $PadSize, $PadSize)
    $aInfo = _GDIPlus_GraphicsMeasureString($hBuffer, $aPad[$iPad][2], $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($hBuffer, $aPad[$iPad][2], $hFont, $aInfo[0], $hFormat, $Brush_Number)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $GUIWidth, $GUIHeight)
    Sleep(100) ;Wirkt realistischer ;)
    If $aPad[$iPad][2] = "OK" Then ;Wenn OK gedrückt, dann...
    If $Key = $Pass Then ;Wenn Passwort richtig, dann...
    MsgBox(64, "Info", "Passwort richtig")
    _Exit()
    Else ;Wenn Passwort falsch, dann...
    MsgBox(16, "Fehler", "Passwort falsch")
    $Key = ""
    $Estimated_Time = TimerInit() ;Zeitlimit wird zurückgesetzt
    Return
    EndIf
    ElseIf $aPad[$iPad][2] = "R" Then ;Wenn Reset gedrückt, dann...
    $Key = "" ;Eingegebene Zeichen werden zurückgesetzt
    Else ;Wenn irgendwas anderes gedrückt, dann...
    $Key &= $aPad[$iPad][2] ;Wert der Gedrückten Taste wird zum String hinzugefügt
    EndIf
    $t = TimerInit()
    Do
    Sleep(10)
    Until TimerDiff($t) > 1000 Or _IsPressed(01)
    EndFunc ;==>_PadEvent

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit() ;Aufräumen ;)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_BrushDispose($Brush_Number)
    _GDIPlus_BrushDispose($Brush_Pad)
    _GDIPlus_BrushDispose($Brush_Pad_Active)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_Exit

    [/autoit]
    • Offizieller Beitrag

    Hallo

    Hab auch irgendwann mal sowas geschrieben, aber ohne GDI ;)
    Hier mal die überarbeitete Version, auch mit AcceleratorKeys, d.h. ihr könnt auch die Tastatur verwenden:

    Spoiler anzeigen
    [autoit]

    #include <EditConstants.au3>
    #include <WindowsConstants.au3>
    $GUIColorBG = 0xFFFFFF ;Hintergrundfarbe der GUI
    $PadColor = 0x000000 ;Farbe der Pads
    $PadTextColor = 0xFFFFFF ;Farbe des Textes auf den Pads
    $ColorActive = 0xFF00FF00 ;Farbe der Pads, wenn aktiviert
    $PadSize = 35 ;Größe der Pads
    $Space = 5 ;Distanz zwischen den Pads
    $PadTextSize = (($PadSize / 2))
    $GUIWidth = ($Space + $PadSize) * 3 - $Space ;GUI Breite (wird aus Padgröße berechnet)
    $GUIHeight = ($Space + $PadSize) * 5 - $Space;GUI Höhe (wird aus Padgröße berechnet)
    $pin_inp = ""

    [/autoit] [autoit][/autoit] [autoit]

    Global $PIN_MaxLen = 7
    Global $PIN = 1234

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)
    GUICreate("PIN", $GUIWidth, $GUIHeight, -1, -1, -1, $WS_EX_TOOLWINDOW)
    GUISetOnEvent(-3, "_Exit")
    GUISetState()
    GUICtrlSetDefBkColor($PadColor)
    GUICtrlSetDefColor($PadTextColor)
    GUISetFont($PadTextSize)
    $hInp = GUICtrlCreateInput("", 0, 0, $GUIWidth, $PadSize + $Space, $ES_READONLY, 0x00020000)
    GUICtrlSetLimit(-1, 5)
    GUICtrlSetFont(-1, $PadTextSize + ($PadSize / 5))

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $x = 0
    Dim $AccelKeys[12][2]
    For $i = 1 To 3
    For $i2 = 0 To 2
    $x += 1
    $AccelKeys[$x - 1][0] = $x
    $AccelKeys[$x - 1][1] = GUICtrlCreateButton($x, $Space * $i2 + $i2 * $PadSize, $Space * $i + $i * $PadSize, $PadSize, $PadSize, 0, 0)
    GUICtrlSetOnEvent(-1, "_btn")
    Sleep(50)
    Next
    Next

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $AccelKeys[9][0] = "r"
    $AccelKeys[9][1] = GUICtrlCreateButton("R", $Space * 0 + 0 * $PadSize, $Space * 4 + 4 * $PadSize, $PadSize, $PadSize)
    GUICtrlSetOnEvent(-1, "_btn")
    Sleep(50)
    $AccelKeys[10][0] = "0"
    $AccelKeys[10][1] = GUICtrlCreateButton("0", $Space * 1 + 1 * $PadSize, $Space * 4 + 4 * $PadSize, $PadSize, $PadSize)
    GUICtrlSetOnEvent(-1, "_btn")
    Sleep(50)
    $AccelKeys[11][0] = "{ENTER}"
    $AccelKeys[11][1] = GUICtrlCreateButton("OK", $Space * 2 + 2 * $PadSize, $Space * 4 + 4 * $PadSize, $PadSize, $PadSize)
    GUICtrlSetOnEvent(-1, "_btn")
    GUISetAccelerators($AccelKeys)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _btn()
    Local $sText = GUICtrlRead(@GUI_CtrlId)
    Local $inpRead = GUICtrlRead($hInp)
    Switch $sText
    Case "R"
    GUICtrlSetData($hInp, "")
    $pin_inp = ""
    Case "OK"
    If $pin_inp = $PIN Then
    GUIDelete()
    MsgBox(0, "", "Jay! Richtiger PIN")
    Exit
    Else
    GUICtrlSetData($hInp, "")
    $pin_inp = ""
    MsgBox(16, "", "Fail!")
    EndIf
    Case Else
    If StringLen($pin_inp) > $PIN_MaxLen - 1 Then Return
    $pin_inp &= $sText
    Local $x = ""
    While StringLen($x) < StringLen($pin_inp) - 1
    $x &= "*"
    WEnd
    GUICtrlSetData($hInp, $x&$sText)
    EndSwitch

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_btn
    Func _Exit()
    Exit
    EndFunc ;==>_Exit

    [/autoit]

    Gruß
    Spider

  • Kanns sein das du ein GDI+ - Fan bist?? ;)
    Ist ziemlich lustig des Ding.
    Kann man ja für andere Sachen benutzen. E-Mail-Einlogger oder so :D .
    Manchmal ist es aber bei mir so, dass die eine Taste mal länger Grün aufleuchtet und auch mal kürzer grün aufleuchtet.