ten1seven / what-input

A global utility for tracking the current input method (mouse/pointer, keyboard or touch).
https://ten1seven.github.io/what-input
MIT License
1.36k stars 89 forks source link

expose `doUpdate` to API #80

Open dailyraisin opened 6 years ago

dailyraisin commented 6 years ago

In cases where one wants to prevent default key events (e.g. stopping, preventDefault), it would be necessary to call doUpdate('intent') manually from the outside as whatInput listeners will not be reached.

ten1seven commented 6 years ago

Interesting! That sounds pretty simple to implement. Do you have a scenario that I could create locally to test against when I add this?

sophieH29 commented 5 years ago

Hi, @dailyraisin @ten1seven I am interested in the same feature. I use React and here is my scenario:

It would be very useful to have access to function like setInput, so I can call on initial onKeyDown handler of component B and update the state accordingly.

@ten1seven let me know what you think

ten1seven commented 5 years ago

Hi @sophieH29, I'm digging into this request. Are you push a specific input to what-input and trigger a doUpdate? Something like this?

whatInput.setInput('keyboard');
sophieH29 commented 5 years ago

Hi @ten1seven, I would rather say just to make current function setInput public, so I will be able to call it onKeyDown event and update state, like

onKeyDown = (ev) => {
...
whatInput.setInput(ev)
...
}
sophieH29 commented 5 years ago

@ten1seven do you plan to make this update to the library?