-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is_action_pressed sometimes skips key press #36396
Comments
Cannot reproduce this on Windows 10 Pro 64 bit, (10.0, Build 18362) Test project for those who need it: var keys_pressed = 0
func _process(_delta):
print(keys_pressed)
if Input.is_action_just_pressed("ui_up"):
keys_pressed += 1
if Input.is_action_just_pressed("ui_down"):
keys_pressed += 1
if Input.is_action_just_pressed("ui_left"):
keys_pressed += 1
if Input.is_action_just_pressed("ui_right"):
keys_pressed += 1
if Input.is_action_just_pressed("x"):
keys_pressed += 1
func _input(event):
if event.is_action_pressed("ui_up"):
keys_pressed += 1
if event.is_action_pressed("ui_down"):
keys_pressed += 1
if event.is_action_pressed("ui_left"):
keys_pressed += 1
if event.is_action_pressed("ui_right"):
keys_pressed += 1
if event.is_action_pressed("x"):
keys_pressed += 1 It prints out the total number of keys you pressed, so just keep pressing all 5 at once and make sure the number is divisible by 10 (2 checks of each type) (Serious) Easy way to press all the arrow keys simultaneously. I had quite a bit of trouble with it. |
@OlegDydy Does this occur if you disable input accumulation by calling |
@Calinou No it does not. I don't use |
@nathanwfranke I think this version (KeyboardTest.zip) of the test demo will be much more informative (and yes, you do not need to press “X” and all the arrow keys, just “X” and any arrow key) extends Node
var keys_pressed = ""
func _process(_delta):
keys_pressed = ""
keys_pressed += "x" if Input.is_action_pressed("x") else "_"
keys_pressed += "^" if Input.is_action_pressed("ui_up") else "_"
keys_pressed += "V" if Input.is_action_pressed("ui_down") else "_"
keys_pressed += "<" if Input.is_action_pressed("ui_left") else "_"
keys_pressed += ">" if Input.is_action_pressed("ui_right") else "_"
print(keys_pressed) If everything is ok, you'll see something like this |
Nope. Pressed X and arrow (and couple of them) at the exact same time. I've been also holding them for longer period to find if they start to flicker - but nothing funky happened - I've always had: x<^ in the output. Maybe it's something with your keybaord config (like key-strokes ratio) on Windows. |
Anyone who can reproduce this, make sure you have an anti-ghosting keyboard and no issues within keyboard testing apps. |
@dreamsComeTrue I ran demo on Linux (on the same machine) and everything was fine. This only happens on Windows. Of course, I do not exclude the possibility of something wrong with my Windows installation, and not with Godot. |
To add on @OlegDydy, here's a snippet to consistently reproduce the bug
Output:
When two actions are in the same frame, only the 2nd action of the frame is detected by the code. |
Godot version:
3.2-stable
OS/device including version:
Windows 10 Home (Version: 1903, Build 18362.657)
Issue description:
Sometimes in-game keystroke events are skipped (this happens often when fps is low). This happens if you press them between frame updates. In my case, this happened with the “X” and arrow buttons. But I think there are many other cases when this can happen.
Steps to reproduce:
To reproduce this problem with a 99% guarantee, you will need to set the
Frame Delay Msec
to high value, for example, to 1000 (1 frame per second). Then need to press any arrow key and then X key (but before next render). In test you'll seex____
Minimal reproduction project:
KeyboardTest.zip (version 2)
If everything is OK, you'll see something like this
x__<_
(pressing left then X) or thisx^___
(pressing up then X)If not, you'll only see
x____
(when pressed any arrow key then X) or even_____
.Frame rate of demo already set to 1 frame per second
My thoughts on this issue:
I downloaded the source code of the engine and did a little research. I think the problem is in the WM_KEYPRESS event (most likely on the Windows side).
As I understand it, this is because the OS sets a flag to indicate that it is a key repeat, regardless of whether the program processed the keystroke or not. Thus, in the WM_KEYPRESS event, the 30th bit of lParam indicates that the arrow key was previously pressed (but the Godot did not know about it).
To fix this problem, it probably makes sense to change the 1183 line of
os_windows.cpp
to something like this:The text was updated successfully, but these errors were encountered: