Keyboard and Controller support for Chromecast
npm install inputcast
import { InputCast } from 'inputcast/sender'
window['__onGCastApiAvailable'] = function(isAvailable) {
if (isAvailable) {
const inputCast = new InputCast()
inputCast.onBeforeGamepad(InputCast.INPUT.R2, event => {
return event
})
inputCast.onBeforeKeyboard(InputCast.INPUT.ALL, event => {
return event
})
}
}import { InputCast } from 'inputcast/receiver'
const inputCast = new InputCast()
inputCast.onGamepad(InputCast.INPUT.R2, event => {
console.log(event)
})
inputCast.onKeyboard(InputCast.INPUT.ALL, event => {
console.log(event)
})//Gamepad interceptor that allows modifying or
//adding data before being sent to the receiver
onBeforeGamepad(
type: string,
cb: (event: GamepadEvent) => Promise<GamepadEvent> | GamepadEvent
)
//Keyboard interceptor that allows modifying or
//adding data before being sent to the receiver
//This event data also includes a `preventDefault`
//function that if called will stop the event from
//propagating to the sender
onBeforeGamepad(
type: string,
cb: (event: KeyboardEvent) => Promise<KeyboardEvent> | KeyboardEvent
)//Event listener for gamepad events
onGamepad(
type: string,
cb: (event: GamepadEvent) => void
)
//Event listener for keyboard events
onGamepad(
type: string,
cb: (event: KeyboardEvent) => void
)InputCast supports all of the available types in the below repo
https://github.com/lmckeen/Gam3pad#available-types
InputCast.INPUT.ALLInputCast also supports all KeyboardEvent types by their respective string based code value
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values