Keyboard Control of Python Script in Mission Planner

I am using my computer with a 3DR telemetry radio and running Python scripts from Mission Planner that have been controlling the copter on a set path. However, I am interested in taking that a step further and writing a Python script to control the quad via keyboard presses (ie yaw left when holding down the left arrow, throttle up when holding down the up arrow). I have written a script using the pygame library that records key presses, but it will not run in Mission Planner, giving me the error:

“Error running script No module named pygame”

I have included the code below. It runs fine as a standalone script, displaying key presses in real time (the print statements were for testing- I would change those to Script.SendRC(…) functions later). But it won’t get past the import statement in Mission Planner, so my questions are:

  1. Is Mission Planner able to import external libraries like pygame?
  2. Are there any other ways to get keyboard input into Mission Planner scripts? (I’ve tried input() and that just stalled at the input line)
  3. Any other suggestions to accomplish this task of controlling the quad via the keyboard?

Thanks for your time, and any input you have to share!


import pygame, sys, time
from pygame.locals import *

size = width, height = 320, 240
screen = pygame.display.set_mode(size)

while 1:
for event in pygame.event.get():
if event.type == QUIT:
if event.type == KEYDOWN:
if event.key == K_LEFT:
elif event.key == K_RIGHT:
elif event.key == K_DOWN:

pygame I don’t beleive will work, what functiosn do you need? keyboard input?

I just need to have control of the Python script from keyboard input. I tried to use input() and raw_input() but those did not work in Mission Planner, either. If you have an idea for how to take input into Mission Planner, I’d like to try it out!

Another option is to try to get Python scripting talking to the copter outside of Mission Planner. Has anyone done that?


If pygame is installed in your machine, and still it is showing no module named pygame, that probably means mission planner is using either its own python api or due to multiple python version installations, some configuration error has occured.