The new Code-a-Key Backpack! Bringing the Makey Makey and the BBC micro:bit together for more invention fun!

Lesson Five: Code Your Key Presses in Scratch

Ready to learn how to code key presses in Scratch? Makey Makey is fun with lots of apps, but once you learn to code your own key presses, the possibilities for inventing are endless!

Get Started in Scratch!

In the last lesson, you drew your own playable instrument. Today, you are going to learn how you can code your own projects in Scratch!

Head to Scratch and create a project along with us! Choose you own characters and backdrops and let's get started! 

If you have not used Scratch with Makey Makey before, the video below is designed as a create-along project!

 

Try following along with the video to code key presses in Scratch. The rest of this class will focus on specific areas of Scratch to help you learn how to create your own game with ease!

Scratch was created at MIT and both of our inventors (Jay and Eric) were actually on the Scratch team! Scratch is a free online coding playground where you can create your own stories, games, and animations with coding blocks.

If it is your first time to look at Scratch, take a moment to look at how everything is laid out. It has code blocks on the left, each grouped by color in palettes for the different things you will want to use to control your sprites: motion, looks, sound, events, control, sensing, operators, variables, and my blocks (where you can create your own blocks.)

To make your sprite (that's what we call a character in your game) do something, you will drag coding blocks to your work area in the center. You can drag a block to the center and then click on it to see what happens to the sprite on the right side. Try dragging the "move 10 steps" block to the work area and then click on it. It will make Scratch cat move, but to have this happen when you press a key press, you'll want to use a hat block to trigger the event. Head to the "Events" palette and try dragging a "When this sprite clicked" block to your work area. Snap the stacking block under the hat block and now you can make Scratch cat move when you click on it.

We can't wait to see your projects play out! Watch our Coding Makey Makey Key presses video to create alongside Colleen. Then spend some time looking over the rest of this lesson and create your own Scratch project. You can tell a story, make an animation, or code a poster in your room to speak! If you want to do something we don't cover in this lesson, head over to the great Scratch tutorials to help you get started creating stories, animations, and sound effects.

Adding Makey Makey Extension

There are lots of ways to code key presses, but it's really quick and easy to add the Makey Makey extension so you know when you are coding with a hat block that will work with your Makey Makey!

A hat block starts a script- think of it as a way to trigger something to happen in your project. Scratch works by connecting stacking blocks to hat blocks. The hat blocks trigger the stacking blocks which instruct the sprites in your project how to behave.

There are tons of possibilities for creating online games, music, and inventing your own applications with Scratch! Things get even more fun when you add extensions to help you connect to real world things! If you have LEGO Mindstorms or a Micro:bit, you can add those extensions too! All of your extensions will show up underneath the "My Blocks" palette.  

Blocks inside the Makey Makey Extension

There are only two hat blocks in our extension. These hat blocks will trigger the stacking blocks you add underneath. These hat blocks trigger events based on key presses. The first one will control what happens when you press one key on your keyboard. If you want to combine key presses to have a special effect, the other block is a "secret code" block with a few different key press options in the dropdown arrow. 

Secret Codes in Scratch

Eric Rosenbaum made this block as a nod to a cheat code known as "The Konami Code." You can also use this extension to put secret codes in your game that add a bonus feature or use it as an integral part of your game. The "when pressed in order" block is based off of secret codes from 1980s Konami games, dubbed "the Konami Code."

↑  ↑  ↓  ↓  ←  →  ← → 

Check out Eric Rosenbaum's Beatbox Quartet and see what happens when you enter the Konami Code! 

Adding Sounds

People love to use Makey Makey and Scratch to create custom sound effects! In fact, the piano app on our webpage is based on a Scratch piano

To add more sounds to your project, click on the "Sounds" tab where you can choose a sound from the Scratch library, record your own sound, or upload a mp3 or wav file to use in your project.

Once you add a sound, you can find it in the "play sound until done" or "start sound" blocks. Try adding both sound blocks to see how they are different. 

Adding Motion

Key presses don't have to only trigger sound effects. You can also make your sprite move. To make a sprite move to the right, there are a couple of different methods! One way is to use the "point in direction" block with the move block. To make your character move to the right, first choose the "point in direction" block and type the variable 90 to point to the right. Add the "move 10 steps" block under the "point in direction" block. Try changing the variable "10" to see how it changes the distance the sprite moves every time you press the right arrow key. You can also change the way your sprite rotates on the screen. To do so,  click on the direction block under the "Stage" area.

Creating and Choosing Random Backdrops

On the far right side of the Scratch window, click on the stage area to access your backdrop tab. Here you can find, edit, or create new backdrops. Add a few to your game so you can see how to use key presses to change backdrops. We like to use backdrops a lot to show a different stage in a game, or show a scene change in a story. For this project, we are using random backdrops to make our "Wizard Girl" sprite magically move to different locations!

To create this script, grab a "switch backdrop to ___" block out of the "Looks" palette, and grab a reporter block from the "Operator" palette that will allow you to "pick random  __ to ___" backdrops. If you create 20 backdrops, you can have this script run on the secret code block and pick one of your 20 random backdrops! 

 

Changing Costumes for Sprites

Changing the costume on your sprite can make your character appear to walk, fly, run, etc! Some sprites already come with new costumes. Click on the costumes tab to change, create, or edit the sprite's costumes. 

Once you are on the "costumes" tab, try drawing, painting, and changing the sprites costumes with the tools available. You can right click to duplicate a costume before you start editing. Make sure to name each costume so you know what to pull up when you are coding key presses in your Scratch project!

 

Control Palette: Hats, If Statements, and Forever Loops

In our next class, we will go further with teaching you some coding skills and computer science lingo to create interactive stories. For now, explore the "Control" palette to tinker with "if blocks" and "forever loops." 

We can't wait to see your Scratch projects! So make sure you share them with us in this Scratch Studio!  

In our next couple of lessons, we will explore different coding platforms!  

Coding Vocabulary

Conditional Statements are used in programming. A conditional statement or expression is a set of rules that happen if a certain condtition is met.

For example, an "if/then statement" is a conditional statement we are using below that states "if the right arrow key is pressed, then change the sprite on the x axis by 10."

We also wrote a script "if the left arrow key is pressed, then change the sprite on the x axis by negative 10."

Scratch scripts run from the hat down. So if you want your Scratch to always look to see if an instance is true, you will want to place your scripts inside a "Forever Loop." A forever loop is a control block. Anything placed inside this block,   will be placed inside an infinite loop that never ends (unless you press the stop sign.)

     

     

    Welcome

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean pharetra, ligula non mollis pretium, lectus libero sodales augue, interdum auctor mauris dui non risus. Nulla facilisi. Nunc rutrum diam in elit sagittis eget viverra erat viverra. Morbi imperdiet aliquet libero vel rhoncus. Integer.