Skip to content

Instantly share code, notes, and snippets.

@ijprest
Created October 6, 2012 20:00
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ijprest/3845947 to your computer and use it in GitHub Desktop.
Save ijprest/3845947 to your computer and use it in GitHub Desktop.
AutoHotkey (AHK) script to generate & paste a new GUID
; Exposes two hotkeys:
; - Win+G generates & pastes a new lowercase guid
; - Win+Shift+G generates & pastes a new UPPERCASE guid
; In both cases, the guid is left on the clipboard so you can easily paste it more than once.
;
GUID()
{
format = %A_FormatInteger% ; save original integer format
SetFormat Integer, Hex ; for converting bytes to hex
VarSetCapacity(A,16)
DllCall("rpcrt4\UuidCreate","Str",A)
Address := &A
Loop 16
{
x := 256 + *Address ; get byte in hex, set 17th bit
StringTrimLeft x, x, 3 ; remove 0x1
h = %x%%h% ; in memory: LS byte first
Address++
}
SetFormat Integer, %format% ; restore original format
h := SubStr(h,1,8) . "-" . SubStr(h,9,4) . "-" . SubStr(h,13,4) . "-" . SubStr(h,17,4) . "-" . SubStr(h,21,12)
return h
}
; Win+G - Generate and paste a GUID
#g::
guid := GUID()
StringLower, guid, guid
Clipboard := guid
SendInput,^v
return
; Win+Shift+G - Generate an UPPERCASE GUID
#+g::
guid := GUID()
StringUpper, guid, guid
Clipboard := guid
SendInput,^v
return
@Jordan466
Copy link

Neat. exactly what I'm looking for

@Flowgun
Copy link

Flowgun commented Feb 25, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment