Is there a way to determine which shift key is pressed? I am writing a program that shows an image and I want the user to say which side of the screen it is showing up on....

I thought of using the mousekeys but realized that not all computers have mousekeys. Is there a way to determine it is the left shift key or the right shift key?

Oh, did I mention that a requirement of the code is that it works on windows, Linux and Mac?

Basically like this even this has busy wait:

import msvcrt

Allways = True

while Allways:
    while not msvcrt.kbhit(): pass ## busy wait, find better way

    print msvcrt.getch()

But this is returning the key press as char, and not giving keycodes.

Better choice would be simple Tkinter program, which catches keyevents, and is cross platform.

ffrom Tkinter import *

root = Tk()

def key(event):    
    frame.focus_force()
    print "pressed", repr(event.keysym)


frame = Frame(root, width=100, height=100)
frame.bind("<Key>", key)
frame.pack()
frame.focus_set()

root.mainloop()

Source: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm

Better choice would be simple Tkinter program, which catches keyevents, and is cross platform.

from Tkinter import *

root = Tk()

def key(event):    
    frame.focus_force()
    print "pressed", repr(event.keysym)


frame = Frame(root, width=100, height=100)
frame.bind("<Key>", key)
frame.pack()
frame.focus_set()

root.mainloop()

Source: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm

Thank you very much! That was really quite impressive!

So that worked but not for my program. I am using wxPython for the program, so it wouldn't really make so much sense to make a Tkinter frame to pick up the keys.

Looks like first f became doubled in my code.

Did you try to google key event wxPython? Or even Daniweb internal search.

Looks like first f became doubled in my code.

Did you try to google key event wxPython? Or even Daniweb internal search.

so in actuality, I misspoke. I am using pyglet, which on some systems recognizes lshift and rshift, but not on all systems. From what I can tell.

Well, most of the page works fine except this section:
Some modifier keys have separate symbols for their left and right sides (however they cannot all be distinguished on all platforms):

key.LCTRL
key.RCTRL
key.LSHIFT
key.RSHIFT

This list has no ALT key, does it work cross platform (I do know that Apple for example uses modifier keys just in opposite way and the name is different (Option and Command, I do not know which correspond which)

Or you could consider using for example numpad Enter and Space Bar.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.