[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Using Pygame to capture key presses for CLI prgram?



This time I'm going to use the USB gamepad method as all I need are a few buttons to change a piece of music that's playing.

I'm making a giant Buzzer game using the Raspberry Pi for the logic and buzzing as well as playing different tunes in the background. When I press a button a can change the tunes.
The Pi will be battery powered and I will be using a battery powered radio with an external input for for the audio as it will be set up in a school playground.

I used the USB input previously for a stepper motor thing I made - 
Blog post with code and explanation for the gamepad and the stepper motors - http://winkleink.blogspot.co.uk/2013/04/raspberry-pi-unipolar-stepper-motors.html
This all worked without a display. I just SSHed into the Raspberry Pi - ran the code and off it went.






On 30 May 2013 09:07, Alec Bennett <wrybread@xxxxxxxxx> wrote:
Please post what you wind up using, this comes up for me pretty often too. In Windows there's a super easy way to get global keypresses, but I haven't found anything in *nix.

Windows method:

i = win32api.GetAsyncKeyState([keycode])




On Thu, May 30, 2013 at 1:02 AM, winkleink <winkleink@xxxxxxxxx> wrote:
James - thank you. I will have a look at your code.
I was getting the feeling that this is how Pygame works.

 Pygame will  read a USB gamepad without any display.
So, somehow a gamepad is different to a keyboard.

Again, thank you for your help.

Albert.


On 30 May 2013 03:50, James Paige [via pygame-users] <[hidden email]> wrote:
A couple years ago I was trying to do something very similar. It wasn't
a raspbery pi, but it was a very small fanless linux box running debian.
In production, it had no monitor and never ran X. All the output was to
a serial LCD and all the input was from a barcode scanner that sent
keypresses as a keyboard.

I tried to use pygame for reading the input, but I finally gave up.
Without a window, pygame is just the wrong tool for the job.

I finally ended up using python's termios module. Here is a small
wrapper that I used http://pastebin.com/q9xMVUSb

I also found the timeout module handy in combination with reading raw
stdin, but whether or not it will be useful for your program I don't know.

---
James Paige

On Wed, May 29, 2013 at 05:05:59PM -0700, winkleink wrote:

> Hi,
>
> I'm running pygame in a raspberry pi.
> The program I am writing has no graphical interface and I am connecting
> using SSH (Putty from a Windows XP computer)
>
> I want to capture a key press (with no graphical interface) and take action.
> Below is my code.  From what I can tell it should work.
>
> Any advice greatly appreciated.
>
>
>
>
>
> --
> View this message in context: http://pygame-users.25799.x6.nabble.com/Using-Pygame-to-capture-key-presses-for-CLI-prgram-tp719.html
> Sent from the pygame-users mailing list archive at Nabble.com.
>



If you reply to this email, your message will be added to the discussion below:
http://pygame-users.25799.x6.nabble.com/Using-Pygame-to-capture-key-presses-for-CLI-prgram-tp719p723.html
To unsubscribe from Using Pygame to capture key presses for CLI prgram?, click here.
NAML



View this message in context: Re: [pygame] Using Pygame to capture key presses for CLI prgram?

Sent from the pygame-users mailing list archive at Nabble.com.