AHK Sketch, an Etch a Sketch, but coded

Post your working scripts, libraries and tools for AHK v1.1 and older
EntropicBlackhole
Posts: 40
Joined: 12 Jun 2021, 15:28

AHK Sketch, an Etch a Sketch, but coded

12 Dec 2021, 22:21

I made a little Etch a Sketch that uses GDI+, there's also a version (https://pastebin.com/DSt9xj1T) that doesn't need the GDI+ file
(Side note: you may want to download the "Rondo" font)

Code: Select all

#SingleInstance, Force
#NoEnv
SetBatchLines, -1
#Include %A_ScriptDir%\Gdip.ahk

if !pToken := Gdip_Startup()
{
    MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
    ExitApp
}
OnExit, Exit
Width := 600
Height := 500
Gui, 1: +E0x80000 +LastFound
Gui, 1: Show

hwnd1 := WinExist()
hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)

pBrush := Gdip_BrushCreateSolid(0xFFFF0000)
Gdip_FillRectangle(G, pBrush, 0, 0, 600, 500)
Gdip_DeleteBrush(pBrush)

pBrush := Gdip_BrushCreateSolid(0xFFFFFFFF)
Gdip_FillEllipse(G, pBrush, 5, 420, 75, 75)
Gdip_FillEllipse(G, pBrush, 520, 420, 75, 75)
Gdip_DeleteBrush(pBrush)


pBrush := Gdip_BrushCreateSolid(0xFFC4C4C4)
Gdip_FillRectangle(G, pBrush, 75, 75, 450, 350) 
Gdip_DeleteBrush(pBrush)

Gdip_TextToGraphics(G, "AHK Sketch", "w450 h75 x80 y10 s40 Center", "Rondo")

UpdateLayeredWindow(hwnd1, hdc, A_ScreenWidth/4+Width/8, A_ScreenHeight/4, Width, Height)
MyPen := Gdip_CreatePen("0xFF000000", 5) 
xPos := BackupX := 300
yPos := BackupY := 250
return

#If WinActive("ahk_id " hwnd1)
a::
d::
s::
w::
#If
dir := (A_ThisHotkey = "s" || A_ThisHotkey = "w") ? "x" : "y"
xdir := (A_ThisHotkey = "s" || A_ThisHotkey = "w") ? "y" : "x"
Backup%dir% := %dir%pos
%xdir%Pos += (A_ThisHotkey = "d" || A_ThisHotkey = "a") ? ((A_ThisHotkey = "d") ? (xPos > 520 ? 0 : 5) : (xPos < 80 ? 0 : -5)) : ((A_ThisHotkey = "s") ? (yPos > 420 ? 0 : 5) : (yPos < 80 ? 0 : -5))
Gdip_DrawLine(G, MyPen, BackupX, BackupY, XPos, YPos)
UpdateLayeredWindow(hwnd1, hdc, A_ScreenWidth/4+Width/8, A_ScreenHeight/4, Width, Height)
return

Esc:: 
Exit:
Gdip_Shutdown(pToken)
ExitApp
Return

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 272 guests