Last active
February 18, 2020 17:16
-
-
Save manciuszz/9115585c6c1d2fbfa486d8a5e1f28482 to your computer and use it in GitHub Desktop.
MSI GS70 Stealth Keyboard Temp Fix.ahk - These notebooks seem to have a really stupid design fault that damages the keyboard flex cable (Source: https://forum-en.msi.com/index.php?topic=180340.0). So, because I couldn't be arsed to fix the hardware - I went the software route. This AutoHotKey script will allow users to use those broken keys by c…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NoEnv | |
#UseHook | |
#Persistent | |
#KeyHistory 0 | |
#SingleInstance Force | |
SetBatchLines, -1 | |
SetKeyDelay, -1, -1 | |
SendMode Input | |
class AppConfig { | |
; ū Ū č Č | |
static symbols := ["u", ["U+010D", "U+010C"], ["U+016B", "U+016A"], "?", "@"] | |
; Intervals in milliseconds | |
static timeOut := 400 | |
static suspenderRefreshInterval := 1000 | |
static upMethodCombo := "LSHIFT & SPACE" | |
static downMethodCombo := "LCTRL & SPACE" | |
static upMethodComboArr := StrSplit(AppConfig.upMethodCombo, " & ") | |
static downMethodComboArr := StrSplit(AppConfig.downMethodCombo, " & ") | |
} | |
class App { | |
static _ := App := new App() | |
__Init() { | |
this.symbols := AppConfig.symbols | |
this.processes := [ | |
(Join, | |
"ahk_exe FortniteClient-Win64-Shipping.exe" | |
"ahk_exe client.exe" | |
)] | |
} | |
__New() { | |
; this._runAsAdmin() | |
this._hooks() | |
this.keyScroller := new App.KeyScroller(this) ;.toggleTimer(ObjBindMethod(this, "__suspender"), AppConfig.suspenderRefreshInterval) | |
this.bindKeys() | |
} | |
_hooks() { | |
DllCall("RegisterShellHookWindow", UInt, A_ScriptHwnd) | |
OnMessage(DllCall("RegisterWindowMessage", Str, "SHELLHOOK"), ObjBindMethod(this, "_shellMessage")) | |
} | |
_runAsAdmin() { | |
if not A_IsAdmin { | |
Run % "*RunAs " A_ScriptFullPath | |
ExitApp | |
} | |
} | |
__suspender() { | |
Suspend, % (this._checkProcesses() ? "On" : "Off") | |
} | |
_shellMessage( wParam, lParam ) { | |
if (wParam = 32772 || wParam = 4) { | |
this.__suspender() | |
} | |
} | |
_checkProcesses() { | |
for index, exeProcess in this.processes | |
if (WinActive(exeProcess)) | |
return true | |
return false | |
} | |
bindKeys() { | |
upMethod := ObjBindMethod(this.keyScroller, "up") | |
downMethod := ObjBindMethod(this.keyScroller, "down") | |
resetMethod := ObjBindMethod(this.keyScroller, "reset") | |
Loop, 26 { | |
Hotkey, % "~*"Chr(A_Index + 96), % resetMethod | |
} | |
Hotkey, ~*BACKSPACE, % resetMethod | |
Hotkey, ~*DELETE, % resetMethod | |
Hotkey, ~*SPACE, % resetMethod | |
Hotkey, % AppConfig.upMethodCombo, % upMethod | |
Hotkey, % AppConfig.downMethodCombo, % downMethod | |
} | |
class KeyScroller { | |
__Init() { | |
this.currentIndex := 0 | |
this.timeout := AppConfig.timeOut | |
} | |
__New(parentInstance) { | |
this.parent := parentInstance | |
this.symbolCount := this.parent.symbols.MaxIndex() | |
this.timerFunc := ObjBindMethod(this, "reset") | |
} | |
up() { | |
if (this.currentIndex == 0) { | |
this.currentIndex := 1 | |
} else if (this.currentIndex == 1) { | |
this.currentIndex := this.symbolCount | |
} else { | |
this.currentIndex := this.currentIndex - 1 | |
} | |
this.sendSymbol() | |
} | |
down() { | |
if (this.currentIndex > this.symbolCount - 1) { | |
this.currentIndex := 0 | |
} else { | |
this.currentIndex := this.currentIndex + 1 | |
} | |
this.sendSymbol() | |
} | |
reset() { | |
this.currentIndex := 0 | |
this.toggleTimer(this.timerFunc, "Off") | |
} | |
toggleTimer(timerFunc, state) { | |
SetTimer, % timerFunc, % state | |
return this | |
} | |
backspace(offset := 0) { | |
; MsgBox % this.currentIndex - offset | |
if (this.currentIndex - offset > 0) | |
Send, {BACKSPACE} | |
} | |
keysAreHeld() { ; Note: KeyWait was too slow (for my liking)... | |
keyState := 0 | |
Loop { | |
spaceState := GetKeyState(AppConfig.upMethodComboArr.2, "P") | |
if (!keyState && spaceState && ( GetKeyState(AppConfig.upMethodComboArr.1, "P") || GetKeyState(AppConfig.downMethodComboArr.1, "P") )) { | |
keyState := A_TickCount | |
} else if (!spaceState) { | |
break | |
} | |
Sleep -1 | |
} | |
return (A_TickCount - keyState) | |
} | |
sendSymbol() { | |
symbolToSend := this.parent.symbols[ this.currentIndex ] | |
this.backspace(1) | |
lowerCaseSymbol := (symbolToSend.MaxIndex() > 0 ? symbolToSend.1 : symbolToSend) | |
Send, {%lowerCaseSymbol%} | |
if (GetKeyState("Capslock", "T") || this.keysAreHeld() > this.timeout - 100) { | |
this.backspace(-1) | |
upperCaseSymbol := (symbolToSend.MaxIndex() > 0 ? symbolToSend.2 : symbolToSend) | |
Send, +{%upperCaseSymbol%} | |
} | |
this.toggleTimer(this.timerFunc, this.timeout) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description:
MSI GS70 Stealth Keyboard Temp Fix.ahk - These notebooks seem to have a really stupid design fault that damages the keyboard flex cable (Source: https://forum-en.msi.com/index.php?topic=180340.0). So, because I couldn't be arsed to fix the hardware - I went the software route. This AutoHotKey script will allow users to use those broken keys by cycling through them via LShift + Space or LCtrl + Space key combos.