Interact window provides incorrect codes on keypress and keydown events #200

Closed
opened 2020-02-16 10:26:08 -06:00 by wooferzfg · 2 comments
wooferzfg commented 2020-02-16 10:26:08 -06:00 (Migrated from github.com)

Whenever a keydown or keypress event gets triggered, event.code gets set to the wrong value.

Expected Behavior

Add the following scripts and then hold down the A key when having any window selected. It should log KeyA for each of the events.

chrome_Fmef3ORunR

chrome_QmuZEl5Ii5

Current Behavior

Add the following scripts and then hold down the A key when having the Browser Source Interact window selected. It logs F7 and an empty string for each of the events.

chrome_kri1BEb3fG

chrome_exgsFEmOY1

Steps to Reproduce

  1. Start OBS with --remote-debugging-port=8081 so you have access to the debug tools.
  2. Create a new scene in OBS Studio, add the Browser source, and point it at the default web page.
  3. Go to http://localhost:8081. Run the following script in the console:
document.addEventListener("keypress", event => {
  console.log(event.code);
});
  1. Right click on the Browser source and click Interact.
  2. Hold down the A key after selecting the Interact window. This results in the wrong key code being logged in the debug console.

Additional information

event.keyCode produces the correct values, but event.code is broken for both the keypress and keydown events.

<!--- The OBS Studio GitHub issue tracker is **ONLY** to be used for reporting bugs that have replication steps. New features should be discussed on our Discord (https://obsproject.com/discord/) or Ideas page (https://ideas.obsproject.com/). For support issues, use the Discord or forums (https://obsproject.com/forum/) --> <!--- Provide a general summary of the issue in the Title above --> Whenever a `keydown` or `keypress` event gets triggered, `event.code` gets set to the wrong value. ## Expected Behavior <!--- Tell us what should happen --> Add the following scripts and then hold down the A key when having any window selected. It should log `KeyA` for each of the events. ![chrome_Fmef3ORunR](https://user-images.githubusercontent.com/8262173/74608312-97831e80-50a5-11ea-9246-f7e1a61eaa53.png) ![chrome_QmuZEl5Ii5](https://user-images.githubusercontent.com/8262173/74608313-97831e80-50a5-11ea-9dcc-ef5a0c3a2720.png) ## Current Behavior <!--- Tell us what happens instead of the expected behavior. --> <!--- Please include a log file here if possible. --> Add the following scripts and then hold down the A key when having the Browser Source Interact window selected. It logs `F7` and an empty string for each of the events. ![chrome_kri1BEb3fG](https://user-images.githubusercontent.com/8262173/74608351-dfa24100-50a5-11ea-97b3-51beb7548d50.png) ![chrome_exgsFEmOY1](https://user-images.githubusercontent.com/8262173/74608352-e03ad780-50a5-11ea-873c-42b13c5effff.png) ## Steps to Reproduce <!--- Provide a link to a live example, or an unambiguous set of steps to --> <!--- reproduce this bug. Include code to reproduce, if relevant. Pictures --> <!--- and video are encouraged if applicable. --> 1. Start OBS with `--remote-debugging-port=8081` so you have access to the debug tools. 2. Create a new scene in OBS Studio, add the Browser source, and point it at the default web page. 3. Go to `http://localhost:8081`. Run the following script in the console: ``` document.addEventListener("keypress", event => { console.log(event.code); }); ``` 4. Right click on the Browser source and click Interact. 5. Hold down the A key after selecting the Interact window. This results in the wrong key code being logged in the debug console. ## Additional information <!--- Not obligatory, but provide any additional details or information --> <!--- that you feel might be relevant to the issue --> `event.keyCode` produces the correct values, but `event.code` is broken for both the `keypress` and `keydown` events.
WizardCM commented 2020-02-21 17:13:38 -06:00 (Migrated from github.com)

I can confirm this is an issue in browser sources.

Tested with: https://keycode.info

Findings:

  • All keypresses are considered from the "general keys" event.location
  • .key and .which are correct
  • event.code returns undefined
  • this works fine in browser panels

There are a few possibilities

  1. Qt isn't correctly passing the events to Cef (may not be fixable by us)
  2. Cef off-screen rendering doesn't track keypresses correctly (may not be fixable by us)
  3. We're doing something wrong
I can confirm this is an issue in browser sources. Tested with: https://keycode.info Findings: * All keypresses are considered from the "general keys" event.location * .key and .which are correct * event.code returns undefined * this works fine in browser panels There are a few possibilities 1. Qt isn't correctly passing the events to Cef (may not be fixable by us) 2. Cef off-screen rendering doesn't track keypresses correctly (may not be fixable by us) 3. We're doing something wrong
WizardCM commented 2020-02-21 18:40:06 -06:00 (Migrated from github.com)

After doing some digging, this is primarily possibility 3, but not in the ways I expected.

  1. This line needs to pull the native_scancode from the event https://github.com/obsproject/obs-browser/blob/master/obs-browser-source.cpp#L303

  2. Modifiers are absolutely not passed correctly. We'll likely have to read the modifiers and convert them to event flags: https://github.com/Dax89/QtCEF/blob/master/QtChromiumPlugin/qquickchromiumwebview.cpp#L412

I will likely do more digging myself, but I'm providing this info to help others in case someone else is interested in trying their hand at fixing this.

After doing some digging, this is primarily possibility 3, but not in the ways I expected. 1. This line needs to pull the `native_scancode` from the event https://github.com/obsproject/obs-browser/blob/master/obs-browser-source.cpp#L303 2. Modifiers are absolutely not passed correctly. We'll likely have to read the modifiers and convert them to event flags: https://github.com/Dax89/QtCEF/blob/master/QtChromiumPlugin/qquickchromiumwebview.cpp#L412 I will likely do more digging myself, but I'm providing this info to help others in case someone else is interested in trying their hand at fixing this.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-obsproject/obs-browser#200
No description provided.