Skip to content

Instantly share code, notes, and snippets.

@bepvte
Last active February 24, 2024 22:55
Show Gist options
  • Save bepvte/213b8597038c97665f1bf988efc4ae3e to your computer and use it in GitHub Desktop.
Save bepvte/213b8597038c97665f1bf988efc4ae3e to your computer and use it in GitHub Desktop.
my autohotkey stuff that fixes my mac layout keyboard
#Requires AutoHotkey v2.0
#Warn
ToTwitterURL() {
MouseGetPos ,, &activehwnd
if WinExist("ahk_class CabinetWClass ahk_id " activehwnd) {
shell := ComObject("shell.application")
windows := shell.Windows()
for val in windows {
if activehwnd == val.HWND {
window := val
break
}
}
if item := window.Document.FocusedItem {
SplitPath item.Path, &filename
CopyTwitterURL(filename)
}
} else {
CopyTwitterURL(A_Clipboard)
}
}
CopyTwitterURL(filename) {
url := RegexReplace(filename, ".*twitter_@(.+)_(\d+)_.*", "https://twitter.com/$1/status/$2")
A_Clipboard := url
}
^!t::ToTwitterURL()
#Requires AutoHotkey v2.0
#Warn ; Enable warnings to assist with detecting common errors.
#SingleInstance Force
SetWorkingDir A_ScriptDir ; Ensures a consistent starting directory.
Persistent
;XButton1::F13
;^SPACE:: Winset, Alwaysontop, , A
ProcessSetPriority "High"
coolboard := 0
devid := "DeviceID LIKE '%VID_24F0&PID_0141%'"
query := "WITHIN 1 WHERE TargetInstance ISA 'Win32_Keyboard' AND TargetInstance." . devid
Init() {
global wmi := ComObjGet("winmgmts:")
global sink := ComObject("WbemScripting.SWbemSink")
ComObjConnect(sink, "SINK_")
wmi.ExecNotificationQueryAsync(sink, "SELECT * FROM __InstanceCreationEvent " . query)
wmi.ExecNotificationQueryAsync(sink, "SELECT * FROM __InstanceDeletionEvent " . query)
CheckWMI()
Suspend False
}
Init()
SINK_OnObjectReady(obj, *) {
;MsgBox(obj.Path_.Class)
switch obj.Path_.Class {
case "__InstanceCreationEvent" : global coolboard := 1
case "__InstanceDeletionEvent" : global coolboard := 0
}
}
CheckWMI() {
res := wmi.ExecQuery("SELECT * FROM Win32_Keyboard WHERE " . devid, "WQL", 0+0)
if (Res.Count >= 1) {
global coolboard := 1
} else {
global coolboard := 0
}
}
Cleanup() {
global coolboard := 0
ComObjConnect(sink)
sink.Cancel()
global sink := ""
global wmi := ""
Suspend True
}
OnPowerBroadcast(wParam, *) {
switch wParam {
; PBT_APMSUSPEND
case 0x4 : Cleanup()
; PBT_APMRESUMESUSPEND
case 0x7 : SetTimer(Init, -1)
}
}
;DEVICE_NOTIFY_WINDOW_HANDLE 0x0
DllCall("RegisterSuspendResumeNotification", "Ptr", A_ScriptHwnd, "UInt", 0x0)
;WM_POWERBROADCAST
OnMessage(0x218, OnPowerBroadcast)
F13::PrintScreen
#Include ExplorerToTwitter.ahk
#HotIf coolboard
LWin::LAlt
LAlt::LWin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment