Re: Read arrow keys

Discussion in 'Python' started by Phil, Feb 21, 2013.

  1. Phil

    Phil Guest

    On 21/02/13 13:36, Ned Deily wrote:
    > In article <>, Phil <>
    > wrote:
    >> I'm attempting to put a simple remote control program together and to do
    >> so I need to check if the arrows are pressed. I could probably do this
    >> with pyqt4 but I'm looking for something simple to experiment with.
    >>


    <cut>

    Thanks for your reply Ned.

    > You don't say which o/s platform(s) you are interested in but, if they
    > are all unix-y and you don't mind running from a shell terminal session,
    > you could just use the venerable curses module in the Python standard
    > library.


    Whatever I manage to cobble together will only be used under Linux.

    I had a look at the curses module and it seems that it will detect key
    presses but I don't know if it will detect two arrow presses at the same
    time, which is what I need.

    I haven't had much success with pygame so I have put something together
    with pyqt4 which almost works.

    def keyPressEvent(self, event):
    self.firstrelease = True
    #astr = "pressed: " + str(event.key())
    self.keylist.append(event.key())

    # the following if and elif statements only detects single key presses
    # key = event.key()
    # if key == QtCore.Qt.Key_Left:
    # print "left"

    # elif key == QtCore.Qt.Key_Up:
    # print "up"

    # elif key == QtCore.Qt.Key_Up and key == QtCore.Qt.Key_Left :
    # print "left and up"

    def keyReleaseEvent(self, event):
    if self.firstrelease == True:
    self.processmultikeys(self.keylist)

    self.firstrelease = False

    del self.keylist[-1]

    def processmultikeys(self,keyspressed):
    print keyspressed


    I'm not sure how to handle "keyspressed". For example, "keyspressed"
    returns 16777235 for "up" and returns 16777234 for "left". What logic do
    I need to detect when "up" and "left" are both pressed?

    Another problem. When "up" and "left" are pressed "keyspessed" returns
    16777235 and 16777234. From then on "keyspressed" always returns
    16777235 and 16777234 even after a single key is pressed. It seems to me
    that "keylist" needs to be emptied. My experiments in this area have
    also not yielded anything useful.

    --
    Regards,
    Phil
     
    Phil, Feb 21, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob R. Ainscough
    Replies:
    0
    Views:
    715
    Rob R. Ainscough
    Jul 20, 2005
  2. Phil

    Read arrow keys

    Phil, Feb 20, 2013, in forum: Python
    Replies:
    0
    Views:
    111
  3. Ned Deily

    Re: Read arrow keys

    Ned Deily, Feb 21, 2013, in forum: Python
    Replies:
    0
    Views:
    137
    Ned Deily
    Feb 21, 2013
  4. Chris Angelico

    Re: Read arrow keys

    Chris Angelico, Feb 21, 2013, in forum: Python
    Replies:
    0
    Views:
    96
    Chris Angelico
    Feb 21, 2013
  5. Ned Deily

    Re: Read arrow keys

    Ned Deily, Feb 21, 2013, in forum: Python
    Replies:
    0
    Views:
    109
    Ned Deily
    Feb 21, 2013
Loading...

Share This Page