Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Read arrow keys

Reply
Thread Tools

Re: Read arrow keys

 
 
Phil
Guest
Posts: n/a
 
      02-21-2013
On 21/02/13 13:36, Ned Deily wrote:
> In article <(E-Mail Removed)>, Phil <(E-Mail Removed)>
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Read arrow keys Ned Deily Python 0 02-21-2013 04:05 AM
Re: Read arrow keys Chris Angelico Python 0 02-21-2013 03:43 AM
Re: Read arrow keys Ned Deily Python 0 02-21-2013 03:36 AM
Read arrow keys Phil Python 0 02-20-2013 11:30 PM
Design time -- can't move Label controls using arrow keys?? Rob R. Ainscough ASP .Net 0 07-20-2005 04:17 AM



Advertisments