Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions windows/detectUSB.ahk
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
#SingleInstance, force
#NoTrayIcon
OnMessage(0x219, "notify_change")
Return
lastkb = ""
DllCall("AllocConsole")
WinHide % "ahk_id " DllCall("GetConsoleWindow", "ptr")
notify_change(wParam, lParam, msg, hwnd)
{
global lastkb
DetectHiddenWindows On
Run %ComSpec%,, Hide, pid
WinWait ahk_pid %pid%
DllCall("AttachConsole", "UInt", pid)
WshShell := ComObjCreate("Wscript.Shell")
exec := WshShell.Exec("cscript /nologo ""%userprofile%\.kinto\usb.vbs""")
kbtype := exec.StdOut.ReadAll()
DllCall("FreeConsole")
Process Close, %pid%
if lastkb != %kbtype%
{
if InStr(kbtype, "Apple")
{
; MsgBox, Apple
Run, "%A_ScriptDir%\NoShell.vbs" "%A_ScriptDir%\toggle_kb.bat" mac, "%A_ScriptDir%"
}
else{
; MsgBox, Windows
Run, "%A_ScriptDir%\NoShell.vbs" "%A_ScriptDir%\toggle_kb.bat" win, "%A_ScriptDir%"
}
; MsgBox % kbtype
}
lastkb = %kbtype%
}
#SingleInstance force
#NoTrayIcon
OnMessage(0x219, notify_change)
Return

lastkb := "`"`""

DllCall("AllocConsole")
WinHide("ahk_id " DllCall("GetConsoleWindow", "ptr"))

notify_change(wParam, lParam, msg, hwnd)
{
global lastkb
DetectHiddenWindows(true)
Run(A_ComSpec, , "Hide", &pid)
WinWait("ahk_pid " pid)
DllCall("AttachConsole", "UInt", pid)
WshShell := ComObject("Wscript.Shell")
exec := WshShell.Exec("cscript /nologo `"%userprofile%\.kinto\usb.vbs`"")
kbtype := exec.StdOut.ReadAll()
DllCall("FreeConsole")
ProcessClose(pid)
if (lastkb != kbtype)
{

if InStr(kbtype, "Apple")
{
; MsgBox, Apple
Run("`"" A_ScriptDir "\NoShell.vbs`" `"" A_ScriptDir "\toggle_kb.bat`" mac", "`"" A_ScriptDir "`"")
}
else{
; MsgBox, Windows
Run("`"" A_ScriptDir "\NoShell.vbs`" `"" A_ScriptDir "\toggle_kb.bat`" win", "`"" A_ScriptDir "`"")
}
; MsgBox % kbtype
}
lastkb := kbtype
}
Loading