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?
Given all that, for those interested, what blocks would you like to see?
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.
Well I tried coding this up but quickly hit a wall . 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.
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
I would love to see this functionality on the official live MakeCode Arcade simulator, to make text input etc. easier and more accessible! Also for text-based games and other use cases than just games, when in the browser on a reglar computer or pad/screen keyboard.
Unless the functionality is already here, with a shortcut, extenstion or the like, to switch from keyboard-gamepad mode to keyboard-keyboard mode to type into ask for string ("") etc., but I just don’t know about it?
I second @Primal_Nexus’ opinion about FPS and many other opportunities and growth potential, too!
mouse.speed(100), mouse.collider(x, y to x, y) "inside the mouse image"or mouse.collider(x, y) “relitive to the mouse”, mouse.addButton(image, x, y), isMouseOn(Sprite), mouse.position()
Is anyone still working on this? I’ve been longing for one of these extensions, but it doesn’t seem to work.
When I copied the link and pasted it on the extensions page, it didn’t appear as an extension.
If anyone can turn it into an extension and post it here, I would be very appreciative. Thank you! (Also sorry in advance if I just entered the wrong link or something, I don’t know much about the GitHub side of MakeCode.)
This is already available in beta, so it will definitely be in the next release! There is a new extension that will add blocks that let you grab mouse and keyboard input. The keyboard support is only intended to give you extra buttons; you can’t use it for typing. That being said, I also will be adding support for keyboard typing in the “ask for string” and “ask for number” blocks in the next release so you can look forward to that. If you want to see the blocks, you can see them in the PR here:
If you would like to try out the new blocks, first please read my standard warnings:
Do not use beta for anything other than looking at new features! Projects created in beta may break at any time and can’t even be shared properly, so seriously, don’t do it.
ONLY VISIT BETA IN AN INCOGNITO WINDOW OR DIFFERENT BROWSER!
If you ignore this, you might end up LOSING ALL OF YOUR PROJECTS.
If you still want to try it out (which I do not recommend) click here
Go to arcade.makecode.com/beta in an incognito window and add the “browser-events” extension to your project.
Nice! -A lot of cool things have been delivered from the @MakeCode team lately!; Online multiplayer, XBox app, kiosk mode(to name a few and sorry for all the other new functionality and improvements I forgot), and now the long awaited keyboard and mouse events extension is soon coming!
Thanks a lot and looking forward to future new exciting things to come!
I just have to say… @MakeCode you guys are absolute CHAMPIONS for adding that in. Not only was that a dream come true to me personally, but you also got my siblings to be super impressed by MakeCode Arcade as a whole! (that’s not an easy feat).
I am working on making a Minecraft dungeons game, and i showed it to my dad, and he said some really good ideas, but i need more buttons than just QWEASD. Is there a way to do that?