Skip to content
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

[BUG] Lost focus when pressing the Escape key #137

Open
hmlendea opened this issue May 16, 2022 · 26 comments
Open

[BUG] Lost focus when pressing the Escape key #137

hmlendea opened this issue May 16, 2022 · 26 comments
Assignees
Labels
bug Something isn't working dependencies This is related to external software that this app depends on mustfix This must be worked on

Comments

@hmlendea
Copy link
Owner

hmlendea commented May 16, 2022

Describe the bug

Whenever the Escape key is pressed, the focus / mouse pointer lock is lost and requires an additional click on the game streaming window to be able to send input again.

Both cursors (the one from the stream, and the local/system one) are visible, but are not in sync - the game one is frozen.

Does not break the game, but it is an annoyance.

To Reproduce

  1. Launch a game (e.g. Factorio)
  2. Start / load a save game
  3. Press the Escape key
  4. The game's menu is displayed but the mouse pointer is unlocked and the game input is lost

Screenshots

No response

Operatingsystem

Arch Linux

Desktop Environment

GNOME 42.1

Installation method

flatpak

Version

1.7.0

Additional context

No response

@hmlendea hmlendea self-assigned this May 16, 2022
@hmlendea hmlendea added the bug Something isn't working label May 16, 2022
@hmlendea
Copy link
Owner Author

My investigations into this matter have not yelded any result.

Apparently, there is an open question on StackOverflow for the root cause of this problem, and hopefully it will receive an answer soon.

@IgorKvasn
Copy link
Contributor

My investigations into this matter have not yelded any result.

Apparently, there is an open question on StackOverflow for the root cause of this problem, and hopefully it will receive an answer soon.

Yes, that was me who asked that question :)
I wanted to fix this highly annoying bug you are describing. I was able to investigate what is the root issue, but I am unable to fix it :(

@hmlendea hmlendea added dependencies This is related to external software that this app depends on mustfix This must be worked on labels May 19, 2022
@UwUnyaa
Copy link

UwUnyaa commented May 19, 2022

I just noticed that having the electron application open causes it to grab the escape key, preventing me from using it outside of the app in any way. This could be specific to X11 though.

@ordy
Copy link

ordy commented Jun 1, 2022

Not sure about the other environments, but I had to downgrade the release from 1.7.0 to 1.5.2 to not have that ESC key issue anymore. I remember facing the same problem on 1.6.0. So something must have changed between 1.5.2 and +1.6.0.
I'm running on arch linux, sway wm (wayland based, but the app is running on xwayland).

@fn-ix
Copy link

fn-ix commented Jun 7, 2022

What about downgrading the version of Electron as a hotfix?

@hmlendea
Copy link
Owner Author

hmlendea commented Jun 7, 2022

It's been an issue for some people even before 1.5.2. GFN handles input locking very weirdly and this kind of issues appears for some but not for others. And whenever I make a fix which seems to work well for me and for others that had the issue before, it's not long until other people report this happening where before it didn't.
Reverting it would have the same effect: "fixing" it for some, and breaking it again for others.

There's another problem with using older electron versions: there's several high-risk security vulnerabilities present which have since been fixed in newer versions.

The best bet would be to finally found a universal and proper fix but so far I wasn't able to.

@UwUnyaa
Copy link

UwUnyaa commented Jun 8, 2022

Right now, I'm using chromium, as it started working again recently. The issue doesn't exist there.

@fn-ix
Copy link

fn-ix commented Nov 30, 2022

Any progress at all on this? It’s an exceedingly annoying bug as it seems to lock out using the escape key in any other app as well...

@glubsy
Copy link

glubsy commented Dec 16, 2022

I thought I had reported this before, maybe not here anyway.
I noticed this issue a few months back and noticed there had been a patch somewhere related to key debouncing or something similar. I think this problem here is related to that.
This is basically due to the fact that the escape key is sent many times in a row over a single frame.

@Lich-Corals
Copy link

Maybe its something with the full screen mode in chrome, the default hotkey to exit it is esc.

@wxlfsangel
Copy link

Hi, Looked through some of the files to find mention of the Escape key and i found this in /opt/geforcenow-electron/resources/app/scripts/main.js

`globalShortcut.register('Esc', async () => {
var window = BrowserWindow.getAllWindows()[0];

  window.webContents.sendInputEvent({
    type: 'keyDown',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'char',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'keyUp',
    keyCode: 'Esc'
  });

  window.webContents.sendInputEvent({
    type: 'keyDown',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'char',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'keyUp',
    keyCode: 'Esc'
  });`

I'm not a programmer so i dont know if modifying something in here would help in disabling the whole losing focus issue.

@Lich-Corals
Copy link

Hi, Looked through some of the files to find mention of the Escape key and i found this in /opt/geforcenow-electron/resources/app/scripts/main.js

`globalShortcut.register('Esc', async () => {
var window = BrowserWindow.getAllWindows()[0];

  window.webContents.sendInputEvent({
    type: 'keyDown',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'char',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'keyUp',
    keyCode: 'Esc'
  });

  window.webContents.sendInputEvent({
    type: 'keyDown',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'char',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'keyUp',
    keyCode: 'Esc'
  });`

I'm not a programmer so i dont know if modifying something in here would help in disabling the whole losing focus issue.

Yes, in some way it does, if you remove the lines, the esc input is completely gone. Without these lines you cannot open pause menus or do anything else that needs the key to be pressed.

@wxlfsangel
Copy link

Hi, Looked through some of the files to find mention of the Escape key and i found this in /opt/geforcenow-electron/resources/app/scripts/main.js
`globalShortcut.register('Esc', async () => {
var window = BrowserWindow.getAllWindows()[0];

  window.webContents.sendInputEvent({
    type: 'keyDown',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'char',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'keyUp',
    keyCode: 'Esc'
  });

  window.webContents.sendInputEvent({
    type: 'keyDown',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'char',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'keyUp',
    keyCode: 'Esc'
  });`

I'm not a programmer so i dont know if modifying something in here would help in disabling the whole losing focus issue.

Yes, in some way it does, if you remove the lines, the esc input is completely gone. Without these lines you cannot open pause menus or do anything else that needs the key to be pressed.

Is there any logic behind the lines repeating though? or is there some other file where the Esc key is set to be the lose focus key and we can change it to a combination like Shift+Esc or F9 or something not used by the game?

@Lich-Corals
Copy link

Hi, Looked through some of the files to find mention of the Escape key and i found this in /opt/geforcenow-electron/resources/app/scripts/main.js
`globalShortcut.register('Esc', async () => {
var window = BrowserWindow.getAllWindows()[0];

  window.webContents.sendInputEvent({
    type: 'keyDown',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'char',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'keyUp',
    keyCode: 'Esc'
  });

  window.webContents.sendInputEvent({
    type: 'keyDown',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'char',
    keyCode: 'Esc'
  });
  window.webContents.sendInputEvent({
    type: 'keyUp',
    keyCode: 'Esc'
  });`

I'm not a programmer so i dont know if modifying something in here would help in disabling the whole losing focus issue.

Yes, in some way it does, if you remove the lines, the esc input is completely gone. Without these lines you cannot open pause menus or do anything else that needs the key to be pressed.

Is there any logic behind the lines repeating though? or is there some other file where the Esc key is set to be the lose focus key and we can change it to a combination like Shift+Esc or F9 or something not used by the game?

I don't know why the code is there multiple times, it worked also with only one time. I didn't find anything else in the code mentioning the esc key, but it's also not my code, so its possible I've missed something.

@fn-ix
Copy link

fn-ix commented Feb 6, 2023

You may be onto something here! There’s some discussion about this over on StackOverflow; it seems it’s necessary to specify char and keyDown at least, but it does seem like the rest may be superfluous. I’ll try to test it out with just the two statements later.

@fn-ix
Copy link

fn-ix commented Feb 6, 2023

Ok, it seems the current solution is a hacky way to get both the in-game response to the Escape key being pressed as well as for GFN to display its own prompt for exiting the session at the same time.

Simply using char has no effect.

Using only keyUp doesn’t have any effect in-game, but immediately brings up the GFN prompt, bringing the mouse out of focus.

Using only keyDown first only has an effect in-game without loss of mouse focus (the desired result), but then about 2 seconds later the GFN prompt appears. It may be behavior somehow coded into GFN itself, hence nothing that could be changed in the Electron wrapper; the current solution just brute-forces both effects to appear simultaneously, since it’s easier to just dismiss the GFN prompt immediately than to have to do it 2 seconds later every time Esc is pressed.

It would be interesting to know the intended behavior on Windows: when exactly does the GFN prompt come up, resulting in loss of focus? Does the user have to press escape several times? It’s possible GFN detects if the user sends any other input after pressing Escape, presumably indicating that they are navigating the in-game menu so that the prompt timer is cancelled; maybe that’s not properly implemented in the Electron wrapper here? Just speculating.

@wxlfsangel
Copy link

Well assuming that GFN can be used on windows in a browser I doubt whoever made it didn't think of the possibility of someone using the escape key within games for menus and the like. Then again it may be an oversight or just how electron apps work on Linux. Still I hope some sort of fix is found, even if it needs some tinkering

@fn-ix
Copy link

fn-ix commented Feb 6, 2023

Yeah, it seems to be related specifically to the electron implementation. Although, again, how does Escape behave on Windows? How does GFN differentiate between whether you want to send the keypress only as an in-game event or as a way to summon the GFN prompt to exit the session? I don’t have access to a Windows machine at the moment, but if someone here does, it might turn out to be pertinent information.

@Lich-Corals
Copy link

Ok, it seems the current solution is a hacky way to get both the in-game response to the Escape key being pressed as well as for GFN to display its own prompt for exiting the session at the same time.

Simply using char has no effect.

Using only keyUp doesn’t have any effect in-game, but immediately brings up the GFN prompt, bringing the mouse out of focus.

Using only keyDown first only has an effect in-game without loss of mouse focus (the desired result), but then about 2 seconds later the GFN prompt appears. It may be behavior somehow coded into GFN itself, hence nothing that could be changed in the Electron wrapper; the current solution just brute-forces both effects to appear simultaneously, since it’s easier to just dismiss the GFN prompt immediately than to have to do it 2 seconds later every time Esc is pressed.

It would be interesting to know the intended behavior on Windows: when exactly does the GFN prompt come up, resulting in loss of focus? Does the user have to press escape several times? It’s possible GFN detects if the user sends any other input after pressing Escape, presumably indicating that they are navigating the in-game menu so that the prompt timer is cancelled; maybe that’s not properly implemented in the Electron wrapper here? Just speculating.

I tried it out on a fresh install of Windows 11 in a virtual machine. The issue is also there in Windows. You mean the Javascript error with the GFN Prompt right?

@hmlendea
Copy link
Owner Author

Is this issue still persisting in the latest version?

@Lich-Corals
Copy link

Yes it is @hmlendea , just tried it out with the new appimage. Thanks for asking :)

@Lich-Corals
Copy link

I got some news on this issue; don't know if it's helpful, but maybe it is.
I've installed the Application from source, and noticed that the issue wasn't there in the first game session started after installation. I stopped the session and started a new one, and the cursor lost focus again every time I pressed the escape key.

Furthermore, I got some errors on while starting with npm start, I'll attach them in a file.
geforcenow-electron.txt

@Saarker
Copy link

Saarker commented Jun 10, 2024

is there any update on the issue? it gets really frustrating on most games out there

@TheFibonacciEffect
Copy link

A workaround currently might be that sometimes the escape key reacts, if it is pressed multiple times in quick succession.

@LayerCZ
Copy link

LayerCZ commented Dec 15, 2024

Any update on this?

@PhoenixAceVFX
Copy link

PhoenixAceVFX commented Dec 26, 2024

i found a fix! just has to be set to be ran every time the page "reloads" or anything so that it stays effective
putting this in the console (control+shift+i to get to devtools) will literally fix this issue
if anyone is having problems just use this every time you start a game (you have to do this every time you start another game)
to unlock your mouse just open the gfn overlay with control+g and close the overlay to return focus
I found this fix while trying to figure out how to do this in electron overall because in cyberpunk 2077 this issue gets annoying REALLY FAST

Note: This was tested on Plasma X11 and Wayland as well as on Hyprland
It works

if (navigator.keyboard && navigator.keyboard.lock){
  navigator.keyboard.lock(['Escape'])
} else {
  console.log("Your app doesn't support navigator.keyboard")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies This is related to external software that this app depends on mustfix This must be worked on
Projects
None yet
Development

No branches or pull requests