Skip to content

Instantly share code, notes, and snippets.

@ashishpatel26
Forked from QuietNoise/G910 Keyboard Fix.ahk
Created October 11, 2022 12:52
Show Gist options
  • Save ashishpatel26/05d093cdfbf3d9562faad6100f9d7366 to your computer and use it in GitHub Desktop.
Save ashishpatel26/05d093cdfbf3d9562faad6100f9d7366 to your computer and use it in GitHub Desktop.
G910 Keyboard Fix for double typing problem

G910 Keyboard Fix

What does this script do?

It's a workaround for broken G910 Logitech keyboards (possibly other keyboards too) whereby some keys occasionally register multiple keystrokes for one kkkkkeypress. The key bug appears because keyboard registers multiple keystrokes in a very short timespan even though you pressed the key only once. This script makes it so the subsequent keystrokes registered in a very short timespan are ignored thus outputing the key only for the first stroke.

How to use this fix?

You need install AutoHotkey (Windows only). https://www.autohotkey.com/. A software to hijack keystrokes and assign them different functions. Then download the G910 Keyboard Fix.ahk file above, change the configuration in it, save and then double click it. You can add this file to Windows autostart if needed.

Configuration

There are two variables that affect the script. The first one brokenKeys is mandatory to be set to fit your scenario. The second one fixOffset is optional:

Line 8: brokenKeys Set this variable so in the quotes there are only your broken keys listed.

Line 16: fixOffset You can leave as is or just to fit your requirements for auto repeat requirements (read comments in code).

Links

Problem with this keyboard is discussed on various forums. https://www.reddit.com/r/LogitechG/comments/b8pqj9/g910_double_typing/ https://www.reddit.com/r/LogitechG/comments/fstryp/g910_keyboard_keys_double_typing/ https://www.reddit.com/r/LogitechG/comments/cu1uaa/ghub_causing_random_keypresses_or_ghostkey/

Other possible solutions

Above links suggest also other possible solutions (none worked for me, hence the script above).

  • Take your keys out and clean you keybard connections,
  • Change USB socket to which the keyboard is connected
  • Type your broken key like crazy for several minute until it fixes itself (some folks suggested it cleans the rust)
  • Quit or uninstall G-Hub
  • Go to Control Panel > Keyboard and change Repeat delay to longer one. Also can try to change slower Repeat rate.
;What does this script do?
;It's a workaround for broken G910 Logitech keyboards (possibly other keyboards too) whereby some keys occasionally register multiple keystrokes for one kkkkkeypress.
;The key bug appears because keyboard registers multiple keystrokes in a very short timespan even though you pressed the key only once.
;This script makes it so the subsequent keystrokes registered in a very short timespan are ignored thus outputing the key only for the first stroke.
;List all your broken keys between quotes below. I.e. if your broken keys are g and f then the line below shoud be
;brokenKeys := "gf"
brokenKeys := "gf"
;timepan in which subsequent keystrokes should be ignored.
;In a typical scenario you yourself won't be pressing a single key faster than 5 times a second (every 200 miliseconds) so it's safe to have this number at 200.
;However, this number also determines how fast autorepeat can happen (when you hold the key).
;The smaller the number the faster the auto repeat speed of the fixed keys will be but also the higher the chance of the key bug happening when you type normally.
;Values higher than 80 seems work best but it might depend on you operating system.
fixOffset := 80
;That's it. There is no need to change anything else below
;These are typical values for a starter AHK script
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;This array will hold timers for each broken key
lastTimePressed := {}
;Create timer with current time for each broken key
Loop, Parse, brokenKeys
{
lastTimePressed[A_LoopField] := A_TickCount
}
;lastTimePressed := A_TickCount
;Assign a hotkey handler for each broken key
Loop, Parse, brokenKeys
{
keyName :=
Hotkey, $%A_LoopField%, HotKeyHandler
}
HotKeyHandler:
pressedKey := SubStr(pressedKey,2)SubStr(A_ThisHotKey,2)
sinceLastPress := A_TickCount - lastTimePressed[pressedKey]
if (sinceLastPress > fixOffset) { ;send the hijacked key only when sufficient time has passed
lastTimePressed[pressedKey] := A_TickCount
Send %pressedKey%
}
return
@Ice2192
Copy link

Ice2192 commented Jul 4, 2024

Do you have like a keyboard syntax or dictionary? In line 8 you have "gf" which does g and f keys. Okay but what if its the enter key in a full keyboard (the one all the way in the bottom right corner). How would you input that in the script?

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