how to ignore the ghost key? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Bootimar
Posts: 8
Joined: 10 Aug 2022, 00:38

how to ignore the ghost key?

05 Aug 2023, 15:23

Hello friends, I appreciate any help.
My keyboard has an issue that when I press W and D at the same time, E is pressed by a ghost! For example, if I press WD my keyboard will type WDE. It is also very annoying in games (while driving a car, if you try to turn right you will jump out of the car!)
What code can I use to ignore the E key while I am pressing W and D at the same time?
Master_X
Posts: 33
Joined: 04 Aug 2023, 13:59

Re: how to ignore the ghost key?

05 Aug 2023, 15:44

simplest idea comes to mind is

Code: Select all

e::
e as defined hotkey which is disabled as input key without any modifiers. Ever tried that?
gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: how to ignore the ghost key?

05 Aug 2023, 16:09

I think keyboard ghosting, actually being a keyboard-specific hardware problem, has its own quirks. I can't reproduce it here, but I would try smth like:

Code: Select all

#If GetKeyState("w", "P") && GetKeyState("d", "P")		; check if w and d are currently pressed
e::return			; disable e
#If
(return stands here for the return statement which you would put at the end of a subroutine or function; you could also put it into the next line(s).)
Like this, e should only be disabled if w and d are pressed at the same time. Otherwise, the e key should still be usable as itself.
If the game runs elevated, your script would need these rights as well.


I would advise against simply using e:: since this would only disable e without side-effects, if absolutely no other code - or if smth like return or exit which ends the subroutine - follows. It also wouldn't be context-sensitive which seems to be requested here.
Consider
Spoiler
Last edited by gregster on 05 Aug 2023, 16:33, edited 1 time in total.
Reason: spoilered code
Master_X
Posts: 33
Joined: 04 Aug 2023, 13:59

Re: how to ignore the ghost key?

05 Aug 2023, 16:21

My first thought was also it's a hardware problem so what to do.

If computer really recognizes the pressed E key you could remap E to be W+D pressed via autohotkey. Since I don't have any keyboards with these problems I cannot test anything. Only problem in any case... you cannot use your E key

I just tried my cheapest 8€ keyboard and it does not do it >.>
User avatar
Bootimar
Posts: 8
Joined: 10 Aug 2022, 00:38

Re: how to ignore the ghost key?

06 Aug 2023, 01:22

Dear @gregster and @Master_X, thank you for your reply.
This code doesn't work for me:

Code: Select all

#If GetKeyState("w", "P") && GetKeyState("d", "P")		; check if w and d are currently pressed
e::return			; disable e
#If
this one e:: works but I cannot use E anymore.

Is there another code to convert WDE to WD, or disable E while I am holding W?

(When I hold WD, my keyboard thinks I am holding WDE physically, so you can test your code by holding WDE)
Master_X
Posts: 33
Joined: 04 Aug 2023, 13:59

Re: how to ignore the ghost key?

06 Aug 2023, 04:32

Tbh, I would buy another keyboard but thats me.

disable e by holding w would be

Code: Select all

#If GetKeyState("w", "P")
e::return
#If 
Since it's a hardware thing, you cannot convert the input in any way. As far I understand the keyboard key w+d gives the computer the e input like if you press e. So you can only handle the pressed E OR the pressed W key OR the pressed D key. But I am also by no means good in this. I may be wrong
gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: how to ignore the ghost key?  Topic is solved

06 Aug 2023, 04:32

Bootimar wrote:
06 Aug 2023, 01:22
This code doesn't work for me:

Code: Select all

#If GetKeyState("w", "P") && GetKeyState("d", "P")		; check if w and d are currently pressed
e::return			; disable e
#If
Your keyboard still sends e while pressing both w and d ?

Just to make sure: Which AHK version are you running?
I am assuming that you are running some recent AHK v1.1.x version. Correct?

If e:: "worked" to completely deactivate e, this single line should as well (just without potential side-effects) in both v1 and v2:

Code: Select all

e::return			; disable e
(When I hold WD, my keyboard thinks I am holding WDE physically, so you can test your code by holding WDE)
No, unfortunately this won't work on my keyboard. If I am already holding w and d, e will never fire when I press it as a third key. That's another hardware limitation of many keyboards: Many three-key combos not consisting of modifiers won't work together. (I would need a different (gaming) keyboard.)

What I can test: Hold w or d, then press e. Not sure if it will help you for the game, but this works for me (I replaced && with ||)

Code: Select all

; #InstallKeybdHook
#Requires AutoHotkey v1.1.33		; require minimum version
#If GetKeyState("w", "P") || GetKeyState("d", "P")		; check if w or d are currently pressed
e::return			; disable e
#If
Since you said that e:: disabled e in your game, I am not assuming that you need to run your script as admin. Still, you could try it with the code above.
You could also add #InstallKeybdHook at the top and see if that helps somehow.

No idea if this can be solved at all with AHK.
User avatar
Bootimar
Posts: 8
Joined: 10 Aug 2022, 00:38

Re: how to ignore the ghost key?

06 Aug 2023, 06:53

Thank you very very much dear @gregster and also @Master_X ! You revived my keyboard! :bravo:
This code perfectly works on any version of AHK:

Code: Select all

; #InstallKeybdHook
#If GetKeyState("w", "P") || GetKeyState("d", "P")		; check if w or d are currently pressed
e::return			; disable e
#If
User avatar
boiler
Posts: 17392
Joined: 21 Dec 2014, 02:44

Re: how to ignore the ghost key?

06 Aug 2023, 08:12

Bootimar wrote: This code perfectly works on any version of AHK:
Actually, it does not work in AHK v2, but it would with a minor change.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Kintaro-OEx, Marium0505, Trunks298 and 170 guests