Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Pixelbox

Create 2D games in JavaScript, made easier · By Cedric Stoquer

Mouse and Keyboard input

A topic by olive created Apr 23, 2020 Views: 431 Replies: 4
Viewing posts 1 to 4
(1 edit)

In project settings it seems that there is some form of Mouse events, but I have been unable to find out how they work.
Is it possible to get the mouse position and buttons that are pressed?

Also a way to get raw keyboard input other than the buttons would be nice, one use would be for typing.

I've figured out how to use the mouse input now, still wondering about keyboard.

agree with this. Event the original have gamepads (which is include the window keyboard) but the scope only buttons

To get raw keyboard input, I would recommend to simply use vanilla JavaScript:

addEventListener('keydown', (event) => {
  // ...
})

see KeyboardEvent for documentation

(1 edit)

That's what I ended up doing in the end, I created a list containing the buttons and if it wasn't in there the program would enter "typing mode"  if you then press enter/escape it will exit that mode and go back into "gamepad" mode, using the engine's gamepad functions.