# Keyboard/mouse input extension

**URL:** https://forum.makecode.com/t/keyboard-mouse-input-extension/5988
**Category:** Arcade
**Tags:** extension
**Created:** [February 5, 2021, 11:48pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988 "2021-02-05T23:48:54Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![eanders](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/eanders/32/3134_2.png) [@eanders](https://forum.makecode.com/u/eanders)
#### Post date: [February 5, 2021, 11:48pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/1 "2021-02-05T23:48:54Z")

</div>

Hi all! In a different thread ([A camera extension?](https://forum.makecode.com/t/a-camera-extension/5950)) 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?**

tagging @omnisImperium @GameGod

---

<div class="post-metadata">

### Author: ![omnisImperium](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/omnisimperium/32/2728_2.png) [@omnisImperium](https://forum.makecode.com/u/omnisImperium)
#### Post date: [February 6, 2021, 1:07am UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/2 "2021-02-06T01:07:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![eanders](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/eanders/32/3134_2.png) [@eanders](https://forum.makecode.com/u/eanders)
#### Post date: [February 7, 2021, 8:17am UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/3 "2021-02-07T08:17:45Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Primal\_Nexus](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/primal_nexus/32/3540_2.png) [@Primal\_Nexus](https://forum.makecode.com/u/Primal_Nexus)
#### Post date: [February 7, 2021, 4:15pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/4 "2021-02-07T16:15:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Vegz78](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/vegz78/32/1201_2.png) [@Vegz78](https://forum.makecode.com/u/Vegz78)
#### Post date: [January 24, 2023, 12:36am UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/5 "2023-01-24T00:36:09Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)
#### Post date: [February 15, 2023, 8:11pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/6 "2023-02-15T20:11:07Z")

</div>

mouse X/mouse Y, mouse in wall, set mouse image to Img, mouse speed

---

<div class="post-metadata">

### Author: ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)
#### Post date: [May 30, 2023, 4:46pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/7 "2023-05-30T16:46:39Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ThemeatIy2](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/themeatiy2/32/14379_2.png) [@ThemeatIy2](https://forum.makecode.com/u/ThemeatIy2)
#### Post date: [August 4, 2023, 5:19pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/9 "2023-08-04T17:19:42Z")

</div>

This is possible on hardware. Just use the pin extension and use [this video](https://www.youtube.com/watch?v=6EP4AaF8HHE)

---

<div class="post-metadata">

### Author: ![Vegz78](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/vegz78/32/1201_2.png) [@Vegz78](https://forum.makecode.com/u/Vegz78)
#### Post date: [September 18, 2023, 5:45pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/10 "2023-09-18T17:45:13Z")

</div>

We are definitely still with you, @eanders! Are you? 😉

What about @jacqueline.russell, @KIKIvsIT, @jwunderl, @richard, @peli and the rest of the great all-star players on the super @MakeCode dream team?

How’s it going with this awesome idea to support keyboard(!!!) and mouse input?

> <https://github.com/microsoft/pxt-arcade/issues/4845>
>
> Teacher request - when students are testing/debugging programs that include a lo…t 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\](https://user-images.githubusercontent.com/22108954/176762595-61ac439b-dded-463e-8e53-f5db835eac20.png)

MakeCode is best, no protest!

V

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [September 18, 2023, 5:46pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/11 "2023-09-18T17:46:06Z")

</div>

@Vegz78 I will do my best to get it into the next release

---

<div class="post-metadata">

### Author: ![Vegz78](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/vegz78/32/1201_2.png) [@Vegz78](https://forum.makecode.com/u/Vegz78)
#### Post date: [September 18, 2023, 5:51pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/12 "2023-09-18T17:51:52Z")

</div>

Thanks, @richard!!! -You are truly our hero and savior!

---

<div class="post-metadata">

### Author: ![Sarge](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarge/32/19590_2.png) [@Sarge](https://forum.makecode.com/u/Sarge)
#### Post date: [September 18, 2023, 6:21pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/13 "2023-09-18T18:21:14Z")

</div>

I might not be a part of the team, but I’m definitely on board!

---

<div class="post-metadata">

### Author: ![TestTube](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@TestTube](https://forum.makecode.com/u/TestTube)
#### Post date: [January 9, 2024, 9:25pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/14 "2024-01-09T21:25:30Z")

</div>

Is anyone still working on this? I’ve been longing for one of these extensions, but it doesn’t seem to work.

> [@Vegz78](#):
>
> How’s it going with this awesome idea to support keyboard(!!!) and mouse input?
> 
> [https://github.com/microsoft/pxt-arcade/issues/4845](https://github.com/microsoft/pxt-arcade/issues/4845)

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

---

<div class="post-metadata">

### Author: ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)
#### Post date: [January 9, 2024, 9:44pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/15 "2024-01-09T21:44:17Z")

</div>

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:

> <https://github.com/microsoft/pxt-common-packages/pull/1467>
>
> This PR adds a browser-only extension that enables support for keyboard and mous…e events.
> 
> There are two more PRs for this, one in pxt-arcade and one in pxt-arcade-sim.
> 
> The API for keyboard keys treats each key as an individual controller button. There is no "get last character typed" block because this API is not meant for typing text, just letting the player have extra button options (typing in our sim would be super cumbersome anyhow given that we have keys that map to special functions like taking a screenshot).
> 
> Also, as an added safety feature all keyboard and mouse events are disabled in mutliplayer (the code doing the disabling is in pxt-arcade-sim).
> 
> !\[image\](https://github.com/microsoft/pxt-common-packages/assets/13754588/830bca55-f70a-4042-b007-66aeddc74173)
> 
> !\[image\](https://github.com/microsoft/pxt-common-packages/assets/13754588/803322ae-bea3-456e-bf86-6da8cd687d8d)

If you would like to try out the new blocks, first please read my standard warnings:

1. **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.
2. 
## 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](http://arcade.makecode.com/beta) in an incognito window and add the “browser-events” extension to your project.

---

<div class="post-metadata">

### Author: ![Vegz78](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/vegz78/32/1201_2.png) [@Vegz78](https://forum.makecode.com/u/Vegz78)
#### Post date: [January 11, 2024, 9:53pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/16 "2024-01-11T21:53:53Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![ChimbroDaPro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/chimbrodapro/32/15852_2.png) [@ChimbroDaPro](https://forum.makecode.com/u/ChimbroDaPro)
#### Post date: [January 12, 2024, 11:20pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/17 "2024-01-12T23:20:10Z")

</div>

> [@Vegz78](#):
>
> A lot of cool things have been delivered from the @MakeCode team lately!

> [@Vegz78](#):
>
> XBox app

_gasp_ MAKECODE ON XBOX… _gasp_ XBOX ON MAKECODE…

Oh yeah, about that…

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

So, uh, thanks!!!

---

<div class="post-metadata">

### Author: ![InvalidProject](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/invalidproject/32/32554_2.png) [@InvalidProject](https://forum.makecode.com/u/InvalidProject)
#### Post date: [January 17, 2024, 6:29pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/18 "2024-01-17T18:29:17Z")

</div>

Zombies of God + Super Makecode Smash???

---

<div class="post-metadata">

### Author: ![Voistrosity](https://avatars.discourse-cdn.com/v4/letter/v/6de8d8/32.png) [@Voistrosity](https://forum.makecode.com/u/Voistrosity)
#### Post date: [March 1, 2024, 2:29am UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/19 "2024-03-01T02:29:36Z")

</div>

Can you add a on mouse moved block(idk if you already did)

---

<div class="post-metadata">

### Author: ![Jedi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jedi/32/14307_2.png) [@Jedi](https://forum.makecode.com/u/Jedi)
#### Post date: [March 1, 2024, 5:20pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/20 "2024-03-01T17:20:53Z")

</div>

they are going to add it as an official feature in the next version, including that (i think)

---

<div class="post-metadata">

### Author: ![145145](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/145145/32/17436_2.png) [@145145](https://forum.makecode.com/u/145145)
#### Post date: [July 23, 2024, 3:54pm UTC](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988/21 "2024-07-23T15:54:47Z")

</div>

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?

[Next page](https://forum.makecode.com/t/keyboard-mouse-input-extension/5988.md?page=2)
