microsoft / pxt-arcade

Arcade game editor based on Microsoft MakeCode
https://arcade.makecode.com
MIT License
478 stars 207 forks source link

Simulator Keyboard Option for web #4845

Open Jaqster opened 2 years ago

Jaqster commented 2 years ago

Teacher request - when students are testing/debugging programs that include a lot of user input ("Ask for String", "Ask for Number" blocks), it gets tiring to constantly use the game pad to enter data. It would be great to be able to substitute a full keyboard input just for the online Simulator for testing purposes.

image

kiki-lee commented 1 year ago

Agreed. We have other ways to simulate input when using the computer that aren't true to the devices, so I don't see a problem with allowing things like using the full keyboard for entering letters (or even using a mouse to navigate and click instead of arrow/A) when using a simulator/phone.

Vegz78 commented 1 year ago

I second this great idea!!!

-Would be a great enhancement both for teaching and debugging to able to:

  1. Type input with keyboard directly into the game.askForString()-method, as suggested here
  2. Type input with keyboard into the console with something like the Python input()-method, or an equivalent console prompt for JavaScript.
  3. Same as point 2, but with the console shown in the simulator(ref. the Console Overlay extension)

(Mouse support would also be great, but that is another issue...) ;-)

Apropos: https://forum.makecode.com/t/keyboard-mouse-input-extension/5988 https://github.com/microsoft/pxt-microbit/issues/3857

Where there is will, there is a way. -You can do it!

Keep up all the great work!

Br, Vegard

UnsignedArduino commented 1 year ago

I think it would be cool if we could get keyboard and mouse and touchscreen events within Arcade. Maybe something like this: (similar to the web APIs)

simulatorOnly.onKeyUp((event: SimulatorOnly.KeyboardEvent) => {
  console.log(event);
});
{
  "key": "u",
  "keyCode": 85,
  "code": "KeyU",
  "altKey": false,
  "ctrlKey": false,
  "metaKey": false,
  "shiftKey": false,
  "repeat": false
}

Similar thing for mouse input. We should do the same for touch screens.

If we have these events implemented, then the game.askForString() function could just set up callbacks for these and it wouldn't complicate the implementation so much, plus then user games can access these as well.

sargedev commented 1 year ago

Perhaps simulator.mouse.x and simulator.mouse.y attributes for accessing the mouse position in code?

Vegz78 commented 1 year ago

And maybe a keyboard shorcut linked to a programmable property to switch between the default gamepad input and the keyboard/mouse modes?

sargedev commented 1 year ago

That's a good idea too! Speaking of which, there's still no shortcut for the menu button 🤔

UnsignedArduino commented 1 year ago

That's a good idea too! Speaking of which, there's still no shortcut for the menu button 🤔

I think ` works now!

Vegz78 commented 1 year ago

Is/should be @riknoll assigned to this, since he might soon already be finished with it?: https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/11