hmlendea / gfn-electron

Linux Desktop client for Nvidia's GeForce NOW game streaming service
GNU General Public License v3.0
488 stars 61 forks source link

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

Open hmlendea opened 2 years ago

hmlendea commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 :(

UwUnyaa commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

What about downgrading the version of Electron as a hotfix?

hmlendea commented 2 years ago

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 commented 2 years ago

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

fn-ix commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

wxlfsangel commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Is this issue still persisting in the latest version?

Lich-Corals commented 1 year ago

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

Lich-Corals commented 6 months ago

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 commented 3 weeks ago

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

TheFibonacciEffect commented 3 weeks ago

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