Keyboard/mouse input extension

Hi all! In a different thread (A camera extension?) there was some interest in a simulator extension to support keyboard and mouse input. I’d like to take a stab at this, or at least get it started for others to take further.

But first a bit about simulator extensions. They’re a little bit different than regular extensions. A traditional extension has one main part: some JavaScript that defines new blocks for you to use in your code. Call this the “block script”. A simulator extension has a block script too, but in addition to that it has another script that runs outside the simulator, in the hosting webpage. Let’s call this the “external script”.

Simulator extensions are a specialty item right now, and not supported by the MakeCode editor itself. When you add a simulator extension to your project, you will see the new blocks it defines and you can code with them, but they won’t do anything. This means you won’t be able to test your code in the editor’s Arcade simulator. For the blocks to function, Arcade needs to be running in a host website that allows the external script to load. The easiest way to do this is to publish your project on GitHub Pages. It is also possible to test on your local machine and I’ll post how to do that later.

Another limitation: it won’t work on hardware, obviously.

Is everyone still with me? :slight_smile:

Given all that, for those interested, what blocks would you like to see?

tagging @omnisImperium @GameGod

4 Likes

I was thinking something like On "left mouse clicked": Do action But you can substitute left mouse for right and vice versa. Or allowing a sprite to look at and turn towards the mouse, allowing the player to aim something like a gun or projectile launcher.

1 Like

Well I tried coding this up but quickly hit a wall :slightly_frowning_face:. I wanted the external script to reach into the simulator iframe and grab the game screen element. The idea was to add event listeners to get mouse events happening within it. But the iframe loads from a different domain, so the browser blocks me from accessing its content. It makes sense; that would be cross-site scripting.

There isn’t a safe workaround, so I’m going to stop here.

1 Like

Hmm yes @eanders I’d say that mouse and keyboard extensions are still new for the community but when they come, first person shooters will come along with LOADS of other opportunities