Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

lmckeen/InputCast

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

InputCast

Keyboard and Controller support for Chromecast


How to use InputCast

npm install inputcast

Sender

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
    })
  }
}

Receiver

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) 
})

API Docs

Sender

//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
)

Receiver

//Event listener for gamepad events
onGamepad(
  type: string,
  cb: (event: GamepadEvent) => void
)

//Event listener for keyboard events
onGamepad(
  type: string,
  cb: (event: KeyboardEvent) => void
)

Available types

Gamepad

InputCast supports all of the available types in the below repo
https://github.com/lmckeen/Gam3pad#available-types

Keyboard

InputCast.INPUT.ALL

InputCast 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


Demo

Live

https://lukemckeen.com/InputCast-Demo/dist/sender

Repo

https://github.com/lmckeen/InputCast-Demo

About

Keyboard and Controller support for Chromecast

Resources

License

Stars

Watchers

Forks

Morty Proxy This is a proxified and sanitized view of the page, visit original site.