Hallo liebe AutoIt-Community,
ich möchte euch hier mein erstes veröffentlichtes Skript vorstellen: ScreenLock.
Sicherlich kennt fast jeder von euch die Handysperre per Muster. Diese habe ich nun in AutoIt umgesetzt, da mir der normale Windows-Sperrbildschirm ziemlich langweilig erschien und ich nicht jedesmal mein Passwort eintippen wollte.
Beim Sperren erscheint eine Vollbild-GUI, auf welcher zum Entsperren das Muster eingegeben werden muss.
Es gibt außerdem ein Skript zum konfigurieren der Farbe, der Abdunklung des Hintergrunds und natürlich des Musters.
Neue Version:
Die Anzahl der Kreise ist nicht mehr auf 3 pro Spalte/Zeile festgelegt, sondern einstellbar.
Es ist auch die Auswahl nur eines Kreises als Muster möglich.
ScreenLock.au3
#cs ----------------------------------------------------------------------------
[/autoit] [autoit][/autoit] [autoit]AutoIt Version: 3.3.8.1
Author: Xenon
Script Function: Locks the screen, for unlocking a code is needed.
[/autoit] [autoit][/autoit] [autoit]#ce ----------------------------------------------------------------------------
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include "BlockInputEx.au3"
#include <Misc.au3>
#include <Array.au3>
#include <String.au3>
Global $bEditMode = False
Global $sIniSection = "ScreenLock"
If $CmdLine[0] >= 1 And $CmdLine[1] = "ChangeCode" Then
$bEditMode = True
$sIniSection = "ScreenLockSettings"
EndIf
Global $sSettingsIni = @ScriptDir & "\Settings.ini"
[/autoit] [autoit][/autoit] [autoit]Global $nCirclesPerRow = Int(IniRead($sSettingsIni, $sIniSection, "Circles", 3))
Global $nCircles = $nCirclesPerRow*$nCirclesPerRow
Global $nRadius = Int((@DesktopHeight-100)/($nCirclesPerRow+($nCirclesPerRow+1)*0.5))*0.5
Global $aState[$nCircles]
Global $aOrder[$nCircles]
Global $nLastCircle = -1
Global $bRun = True
Global $bCodeRight = True
For $i = 0 To $nCircles-1
$aOrder[$i] = -1
Next
; Tastatur sperren
If Not $bEditMode Then _BlockInputEx(3)
; GUI erstellen
$hGUI = GUICreate("ScreenLock", @DesktopWidth + 10, @DesktopHeight + 10, -5, -5, $WS_POPUP, $WS_EX_TOPMOST)
GUICtrlCreatePic("",0,0, @DesktopWidth + 10,@DesktopHeight + 10)
; Farbe = schwarz
GUISetBkColor (0x000000, $hGUI)
; Transparenz aus Settings.ini
WinSetTrans ($hGUI, "", IniRead($sSettingsIni, $sIniSection, "Transparency", 125))
; Eingabefeld erstellen
$hChildInput = GUICreate("ScreenLockInput", @DesktopHeight-100, @DesktopHeight - 100, Int((@DesktopWidth-@DesktopHeight+100)*0.5)+10, 100+10, $WS_POPUP,$WS_EX_LAYERED+$WS_EX_MDICHILD+$WS_EX_TOPMOST, $hGUI)
GUISetBkColor(0x050505, $hChildInput)
_WinAPI_SetLayeredWindowAttributes($hChildInput, 0x050505)
; Text-GUI
$hChildCaption = GUICreate("ScreenLockCaption", @DesktopHeight-100, 50, Int((@DesktopWidth-@DesktopHeight+100)*0.5)+10, 25+10, $WS_POPUP,$WS_EX_LAYERED+$WS_EX_MDICHILD+$WS_EX_TOPMOST, $hGUI)
GUISetBkColor(0xABCDEF, $hChildCaption)
$hLabelCaption = GUICtrlCreateLabel("Code eingeben", (@DesktopHeight-219-100)*0.5, 8, 219, 41)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, IniRead($sSettingsIni, $sIniSection, "Color", "0x00FF00"))
_WinAPI_SetLayeredWindowAttributes($hChildCaption, 0xABCDEF)
; Alles anzeigen
GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_DISABLE, $hGUI)
GUISetState(@SW_SHOW, $hChildInput)
GUISetState(@SW_SHOW, $hChildCaption)
_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]; Buffer erstellen
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hChildInput)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopHeight-100, @DesktopHeight-100, $hGraphic)
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode ($hBuffer, 2)
_GDIPlus_GraphicsSetSmoothingMode ($hGraphic, 2)
; Brushs und Pens erstellen
$hBrushActivated = _GDIPlus_BrushCreateSolid (Dec("FF" & StringReplace(IniRead($sSettingsIni, $sIniSection, "Color", "0x00FF00"), "0x", "")))
$hBrushInvisible = _GDIPlus_BrushCreateSolid (0xFF050505)
$hBrushRed = _GDIPlus_BrushCreateSolid (0xFFFF0000)
$hBrushWhite = _GDIPlus_BrushCreateSolid (0xFFFFFFFF)
$hPenActivated = _GDIPlus_PenCreate (Dec("FF" & StringReplace(IniRead($sSettingsIni, $sIniSection, "Color", "0x00FF00"), "0x", "")), 6, 2)
$hPenRed = _GDIPlus_PenCreate (0xFFFF0000, 6, 2)
$hPenBlack = _GDIPlus_PenCreate (0xFF000000, 12, 2)
; Alles zeichnen
_Render ()
; Dauerschleife
While $bRun
; Andere Fenster in den Hintergrund
If Not WinActive ("ScreenLockInput") And Not $bEditMode Then
WinActivate ("ScreenLockInput")
EndIf
; Überprüfen, ob linke Maustaste noch gedrückt, wenn ja, Abstand zu allen Kreisen berechen:
$aCursorInfo = GUIGetCursorInfo ($hChildInput)
If $aCursorInfo[2] Then
$MousePosition = MouseGetPos ()
For $i = 0 To $nCirclesPerRow-1 ; Alle Kreise durchlaufen
For $j = 0 To $nCirclesPerRow-1
If Sqrt (($MousePosition[0] - ($i *$nRadius*3+2*$nRadius + Int((@DesktopWidth-@DesktopHeight+100)*0.5)))*($MousePosition[0] - ($i *$nRadius*3+2*$nRadius + Int((@DesktopWidth-@DesktopHeight+100)*0.5))) + _
($MousePosition[1] - ($j *$nRadius*3+2*$nRadius + 100)) * ($MousePosition[1] - ($j *$nRadius*3+2*$nRadius + 100))) <= $nRadius Then ;Abstand nach Pythagoras
$aState[$i*$nCirclesPerRow+$j] = 1
If $nLastCircle <= $nCircles-1 And _ArraySearch ($aOrder, $i * $nCirclesPerRow + $j) = -1 Then
$nLastCircle += 1
$aOrder[$nLastCircle] = $i * $nCirclesPerRow + $j
_Render ()
EndIf
If $nLastCircle >= $nCircles-1 And Not _CheckCode () Then
_Render (True)
Sleep (1500)
For $i = 0 To $nCircles-1
$aOrder[$i] = -1
$aState[$i] = 0
Next
$nLastCircle = -1
_Render ()
EndIf
EndIf
Next
Next
Else
If $aOrder[0] <> -1 And Not _CheckCode () Then
_Render (True)
Sleep (1500)
For $i = 0 To $nCircles-1
$aOrder[$i] = -1
$aState[$i] = 0
Next
$nLastCircle = -1
_Render ()
EndIf
EndIf
WEnd
; Ressourcen freigeben
_GDIPlus_PenDispose ($hPenActivated)
_GDIPlus_PenDispose ($hPenRed)
_GDIPlus_PenDispose ($hPenBlack)
_GDIPlus_BitmapDispose ($hBitmap)
_GDIPlus_BrushDispose ($hBrushActivated)
_GDIPlus_BrushDispose ($hBrushInvisible)
_GDIPlus_BrushDispose ($hBrushRed)
_GDIPlus_BrushDispose ($hBrushWhite)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
[/autoit] [autoit][/autoit] [autoit]If Not $bEditMode Then _BlockInputEx (0) ; Tastatur entsperren
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func _CreateCircle ($nColor, $nCenterX, $nCenterY) ; $nColor - Farbe (0-weiß, 1-aktive Farbe, 2-Fehler) ; $nCenterX/Y - Mittelpunkt des zu zeichnenden Kreises (Koordinaten)
Local $nWidth1 = 10
Local $nWidth2 = 20
Local $nWidth3 = 60
Local $hBrush
If $nColor = 0 Then
$hBrush = _GDIPlus_BrushClone ($hBrushWhite)
ElseIf $nColor = 1 Then
$hBrush = _GDIPlus_BrushClone ($hBrushActivated)
ElseIf $nColor = 2 Then
$hBrush = _GDIPlus_BrushClone ($hBrushRed)
EndIf
_GDIPlus_GraphicsFillEllipse($hBuffer, $nCenterX - $nRadius , $nCenterY - $nRadius , 2*$nRadius , 2*$nRadius)
_GDIPlus_GraphicsFillEllipse($hBuffer, $nCenterX - $nRadius + Round($nRadius/100*$nWidth1), $nCenterY - $nRadius + Round($nRadius/100*$nWidth1), 2*$nRadius - Round($nRadius/100*2*$nWidth1), 2*$nRadius - Round($nRadius/100*2*$nWidth1), $hBrush)
_GDIPlus_GraphicsFillEllipse($hBuffer, $nCenterX - $nRadius + Round($nRadius/100*$nWidth2), $nCenterY - $nRadius + Round($nRadius/100*$nWidth2), 2*$nRadius - Round($nRadius/100*2*$nWidth2), 2*$nRadius - Round($nRadius/100*2*$nWidth2))
_GDIPlus_GraphicsFillEllipse($hBuffer, $nCenterX - $nRadius + Round($nRadius/100*$nWidth3), $nCenterY - $nRadius + Round($nRadius/100*$nWidth3), 2*$nRadius - Round($nRadius/100*2*$nWidth3), 2*$nRadius - Round($nRadius/100*2*$nWidth3), $hBrush)
_GDIPlus_BrushDispose ($hBrush)
EndFunc ; _CreateCircle ($nColor, $nCenterX, $nCenterY)
Func _Render ($bWrongCode = False) ; $bWrongCode - Falscher Code eingegeben? (standart: nein)
[/autoit] [autoit][/autoit] [autoit]; unsichtbarer Hintergrund
_GDIPlus_GraphicsFillRect ($hBuffer, -1, -1, @DesktopWidth+2, @DesktopWidth+98, $hBrushInvisible)
If Not $bWrongCode Then
[/autoit] [autoit][/autoit] [autoit]; kein falscher Code -> Standardfarben
If Not $bCodeRight Then
GUICtrlSetData ($hLabelCaption, "Code eingeben")
GUICtrlSetColor($hLabelCaption, IniRead($sSettingsIni, "ScreenLock", "Color", "0x00FF00"))
$bCodeRight = True
EndIf
; alle Linien zeichnen
For $i = 1 To $nCircles-1
If $aOrder[$i] = -1 Then ExitLoop
_GDIPlus_GraphicsDrawLine ($hBuffer, Int($aOrder[$i-1]/$nCirclesPerRow) *$nRadius*3+2*$nRadius, Mod($aOrder[$i-1], $nCirclesPerRow)*$nRadius*3+2*$nRadius, Int($aOrder[$i]/$nCirclesPerRow) *$nRadius*3+2*$nRadius, Mod($aOrder[$i], $nCirclesPerRow)*$nRadius*3+2*$nRadius, $hPenBlack)
_GDIPlus_GraphicsDrawLine ($hBuffer, Int($aOrder[$i-1]/$nCirclesPerRow) *$nRadius*3+2*$nRadius, Mod($aOrder[$i-1], $nCirclesPerRow)*$nRadius*3+2*$nRadius, Int($aOrder[$i]/$nCirclesPerRow) *$nRadius*3+2*$nRadius, Mod($aOrder[$i], $nCirclesPerRow)*$nRadius*3+2*$nRadius, $hPenActivated)
Next
;Kreise erstellen
For $i = 0 To $nCirclesPerRow-1
For $j = 0 To $nCirclesPerRow-1
_CreateCircle ($aState[$i*$nCirclesPerRow+$j], $i*$nRadius*3+2*$nRadius, $j*$nRadius*3+2*$nRadius)
Next
Next
Else
; falscher Code -> rote Farbe
If $bCodeRight Then
GUICtrlSetData ($hLabelCaption, "Falscher Code")
GUICtrlSetColor($hLabelCaption, 0xFF0000)
$bCodeRight = False
EndIf
; alle Linien zeichnen
For $i = 1 To $nCircles-1
If $aOrder[$i] = -1 Then ExitLoop
_GDIPlus_GraphicsDrawLine ($hBuffer, Int($aOrder[$i-1]/$nCirclesPerRow) *$nRadius*3+2*$nRadius, Mod($aOrder[$i-1], $nCirclesPerRow)*$nRadius*3+2*$nRadius, Int($aOrder[$i]/$nCirclesPerRow)*$nRadius*3+2*$nRadius, Mod($aOrder[$i], $nCirclesPerRow)*$nRadius*3+2*$nRadius, $hPenBlack)
_GDIPlus_GraphicsDrawLine ($hBuffer, Int($aOrder[$i-1]/$nCirclesPerRow) *$nRadius*3+2*$nRadius, Mod($aOrder[$i-1], $nCirclesPerRow)*$nRadius*3+2*$nRadius, Int($aOrder[$i]/$nCirclesPerRow)*$nRadius*3+2*$nRadius, Mod($aOrder[$i], $nCirclesPerRow)*$nRadius*3+2*$nRadius, $hPenRed)
Next
;Kreise erstellen
For $i = 0 To $nCirclesPerRow-1
For $j = 0 To $nCirclesPerRow-1
_CreateCircle (2, $i*$nRadius*3+2*$nRadius, $j*$nRadius*3+2*$nRadius)
Next
Next
EndIf
; alles auf GUI anzeigen
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, @DesktopHeight-100, @DesktopHeight-100)
EndFunc
[/autoit] [autoit][/autoit] [autoit]Func _CheckCode ()
Local $sCode = ""
; Code entsteht aus zusammensetzen der Reihenfolge zu einem String
For $i = 0 To $nCircles-1
If $aOrder[$i] <> -1 Then
$sCode &= $aOrder[$i]
Else
ExitLoop
EndIf
Next
[/autoit] [autoit][/autoit] [autoit]If Not $bEditMode Then
; Wenn .ini-Code leer oder gleich dem Eingegebenen, dann Programm beenden
If IniRead ($sSettingsIni, "ScreenLock", "Code", "") = "" Or IniRead ($sSettingsIni, "ScreenLock", "Code", "") == _StringEncrypt (1, $sCode, $sCode, 3) Then
$bRun = False
Return True ;richtiger Code
EndIf
Return False ;falscher Code
Else
IniWrite ($sSettingsIni, $sIniSection, "Code", _StringEncrypt (1, $sCode, $sCode, 3))
$bRun = False
Return True
EndIf
EndFunc
[/autoit]ScreenLockSettings.au3
#cs ----------------------------------------------------------------------------
[/autoit] [autoit][/autoit] [autoit]AutoIt Version: 3.3.8.1
Author: Xenon
Script Function: Changes the settings for the ScreenLock script.
[/autoit] [autoit][/autoit] [autoit]#ce ----------------------------------------------------------------------------
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <Process.au3>
; Variablen
Global $sSettingsIni = @ScriptDir & "\Settings.ini"
Global $nColor = Dec(StringReplace(IniRead ($sSettingsIni, "ScreenLock", "Color", "0x00FF00"), "0x", ""))
Global $nTempColor = 0
Global $nTransparency = IniRead ($sSettingsIni, "ScreenLock", "Transparency", 125)
Global $nCirclesPerRow = IniRead ($sSettingsIni, "ScreenLock", "Circles", 3)
Global $sCode = IniRead ($sSettingsIni, "ScreenLock", "Code", "")
#Region ### GUI
$hGUI = GUICreate("ScreenLock - Optionen", 553, 492, 192, 124)
$hLabel1 = GUICtrlCreateLabel("Transparenz des Sperrbildschirms:", 16, 40, 198, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$hTransparency = GUICtrlCreateSlider(40, 72, 425, 41)
GUICtrlSetLimit(-1, 255, 1)
GUICtrlSetData(-1, $nTransparency)
$hLabel2 = GUICtrlCreateLabel("Transparent", 24, 120, 61, 17)
$hLabel3 = GUICtrlCreateLabel("Nicht transparent", 416, 120, 85, 17)
$hLabel4 = GUICtrlCreateLabel("Muster:", 16, 160, 46, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$hColor = GUICtrlCreateButton("Farbe ändern", 325, 250, 129, 33)
$hCode = GUICtrlCreateButton("Muster ändern", 325, 315, 129, 33)
$hLabel5 = GUICtrlCreateLabel ("Anzahl der Kreise je Reihe bzw. Spalte:", 20, 200)
$hCircles = GUICtrlCreateSlider (210, 197, 250, 30)
GUICtrlSetLimit(-1, 7, 2)
GUICtrlSetData(-1, $nCirclesPerRow)
$hLabel6 = GUICtrlCreateLabel (GUICtrlRead($hCircles), 470, 200)
$hLabel7 = GUICtrlCreateLabel("Farbe der Kreise:", 20, 260)
$hLabel8 = GUICtrlCreateLabel("Muster:", 20, 320)
$hSave = GUICtrlCreateButton("OK", 145, 432, 121, 33)
$hExit = GUICtrlCreateButton("Abbrechen", 275, 432, 121, 33)
$hShowColor = GUICtrlCreateGraphic(150, 255, 150, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion
GUICtrlSetBkColor($hShowColor, $nColor)
GUICtrlSetData ($hTransparency, $nTransparency)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $hExit
Exit
Case $hColor
; Farbe wählen
$nTempColor = _ChooseColor (2, $nColor, 2, $hGUI)
If $nTempColor <> -1 And $nTempColor <> 0x000000 Then
$nColor = $nTempColor
GUICtrlSetBkColor($hShowColor, $nColor)
EndIf
Case $hCode
IniWrite ($sSettingsIni, "ScreenLockSettings", "Color", "0x" & Hex($nColor, 6))
IniWrite ($sSettingsIni, "ScreenLockSettings", "Transparency", GUICtrlRead($hTransparency))
IniWrite ($sSettingsIni, "ScreenLockSettings", "Circles", GUICtrlRead($hCircles))
If FileExists (@ScriptDir & "\ScreenLock.au3") Then
_RunDos (@ScriptDir & "\ScreenLock.au3 ChangeCode")
ElseIf FileExists (@ScriptDir & "\ScreenLock.exe") Then
Run (@ScriptDir & "\ScreenLock.exe ChangeCode")
Else
MsgBox (16, "ScreenLock", "Es wurde im Skriptverzeichnis keine Datei" & @CRLF & "'ScreenLock.au3' bzw. 'ScreenLock.exe'" & @CRLF & "gefunden. Muster ändern nicht möglich!", 0, $hGUI)
EndIf
$sCode = IniRead ($sSettingsIni, "ScreenLockSettings", "Code", "")
[/autoit] [autoit][/autoit] [autoit]Case $hSave
If $sCode = "" Then
MsgBox (16, "ScreenLock", "Es wurde kein Code angegeben!", 0, $hGUI)
Else
IniWrite ($sSettingsIni, "ScreenLock", "Color", "0x" & Hex($nColor, 6))
IniWrite ($sSettingsIni, "ScreenLock", "Transparency", GUICtrlRead($hTransparency))
IniWrite ($sSettingsIni, "ScreenLock", "Circles", GUICtrlRead($hCircles))
IniWrite ($sSettingsIni, "ScreenLock", "Code", $sCode)
Exit
EndIf
Case $hCircles
GUICtrlSetData ($hLabel6, GUICtrlRead($hCircles))
EndSwitch
WEnd
Achtung: Damit die Konfigurationen wirksam werden, müssen sich beide .au3-Dateien im selben Ordner befinden.
Weiterhin wird für das Sperren des Desktops die Datei "BlockInputEx.au3" benötigt, erhältlich hier.
Tipp: Sollte man den Code jedoch einmal vergessen haben, so hilft immer nocht Strg+Alt+Entf!
Ich freue mich schon auf Kritik bzw. Lob.
MfG Xenon