-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
Physical Keyboard Input Listener doesn't work without input #1807
Comments
Misunderstood docs |
I do not have an actual input to target. It looks like my keyboard input is picked up by RSK, however, it's not running the input through onChange or onKeyPress. When hitting my keyboard I get this message: |
Hello @SonnyBrooks, the caret position reset is an internal construct to prevent edge cases. Essentially, when you interact outside of the keyboard, the caret position is set back to What you're asking for might be provided by the following options, but I don't know what's your current implementation so this may vary: https://hodgef.com/simple-keyboard/documentation/options/physicalkeyboardhighlight/ Regards, |
Those options are just visual aren't they? Here's my implementation: <Keyboard
keyboardRef={r => (keyboard.current = r)}
theme={"hg-theme-default w-custom-theme"}
layout={layout}
display={display}
mergeDisplay={true}
onChange={e => onChange(e)}
onKeyPress={e => onKeyPress(e)}
physicalKeyboardHighlightPress={true}
physicalKeyboardHighlight={true}
buttonAttributes={
[
{
attribute: "disabled",
value: "true",
buttons: "{space}"
}
]
}
/>
function onChange(input) {
if(input.length > 5)
keyboard.current.setInput(input.substr(0, 5));
setCoolAttr(input);
} else {
keyboard.current.setInput(input.trim())
}
} When I press my physical keyboard, onChange receives no events. |
Check out this demo: When you click the preview space and hit your keyboard keys, are simple-keyboard buttons triggered? Normally that should be the case. The docs links above have a brief explanation for each option. Let me know if it still doesn't work - thanks! |
Yes, the keys work as expected in the demo. I tried to translate them to my implementation: import Keyboard from 'react-simple-keyboard';
const onChange = (input) => {
console.log(input);
}
const onKeyPress = (input) => {
console.log(input)
}
return (
<div className="max-w-screen-sm m-auto">
<Keyboard
keyboardRef={r => (keyboard.current = r)}
theme={"hg-theme-default myTheme1"}
layout={layout}
display={display}
mergeDisplay={true}
onChange={onChange}
onKeyPress={onKeyPress}
physicalKeyboardHighlightPress={true}
physicalKeyboardHighlight={true}
buttonAttributes={
[
{
attribute: "disabled",
value: "true",
buttons: "{space}"
}
]
}
/>
</div>
) When clicking on the digital keyboard, I get the logs as expected. When I hit my physical keyboard, no logs are recorded. |
Sorry, I still cannot repro the issue that you're experiencing. Could you provide a full sandbox link or test git repository showing the issue? I will reopen the ticket once I get that. Thanks! |
Here's my repro - https://codesandbox.io/s/divine-feather-zq2lij?file=/src/components/Game/GameKeyboard.jsx This issue is being experienced on Chrome, Brave, and Edge. |
I see what my issue is. On my keyboard, I'm not using SHIFT to type Cap Q. I can add a text-transform on those buttons to make them uppercase and switch my display back to all lowercase. I don't know if an Regardless, thanks for looking into this, much appreciated. |
Yes that would be helpful indeed, although a bit tricky to roll out due to the current logic. I added this as a Proposal so I can pick it up in the future. Thanks! |
Is your feature request related to a problem? Please describe.
When using a physical keyboard, input does not go through the onChange/onKeyPress.
Debug shows that it is hearing the key events but the events are not running through the proper functions.
Caret position reset due to "keyup" event
Digital keyboard works as expected, even without input target.
Describe the solution you'd like
When I type on my keyboard, I expect my input to run thought RSK's built in onChange, onKeyPress, etc functions - even if I don't have a specified input target.
Describe alternatives you've considered
Other solutions would be to implement key listeners outside of RSK.
Additional context
More context can be added based on questions about the requested feature.
The text was updated successfully, but these errors were encountered: