Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39404

Re: Read arrow keys

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <phil_lor@bigpond.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'elif': 0.04; 'works.': 0.07; 'python': 0.09; 'event):': 0.09; 'linux.': 0.09; 'logic': 0.09; 'subject:keys': 0.09; 'def': 0.10; 'curses': 0.16; 'detects': 0.16; 'experiments': 0.16; 'pressed': 0.16; 'pygame': 0.16; 'true:': 0.16; 'wrote:': 0.17; 'detect': 0.17; 'shell': 0.18; 'module': 0.19; 'skip:p 30': 0.20; "haven't": 0.23; 'seems': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'library.': 0.27; 'received:10.0.0': 0.28; 'attempting': 0.29; 'statements': 0.29; 'probably': 0.29; "i'm": 0.29; 'problem.': 0.32; 'running': 0.32; 'could': 0.32; 'print': 0.32; 'skip:s 30': 0.33; 'handle': 0.33; 'received:10.0': 0.33; 'to:addr:python- list': 0.33; 'another': 0.33; 'thanks': 0.34; 'whatever': 0.35; 'false': 0.35; 'skip:k 20': 0.35; 'remote': 0.35; 'something': 0.35; 'but': 0.36; 'anything': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'received:10': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'your': 0.60; 'time,': 0.62; 'success': 0.63; 'useful.': 0.65; 'reply': 0.66; 'received:61': 0.75; 'article': 0.78; 'experiment': 0.84; 'yielded': 0.84; 'phil': 0.91
X-Authentication-Info Submitted using ID phil_lor@bigpond.com
X-Authority-Analysis v=2.0 cv=D/zF24tj c=1 sm=1 a=MjWgaz5//csVbyNlFB2lbA==:17 a=pTzqZbqM9tkA:10 a=JDadKst33uMA:10 a=8nJEP1OIZ-IA:10 a=1IlZJK9HAAAA:8 a=vX7WZfq4K6gA:10 a=eaX4f-cdecK1n17hcJkA:9 a=wPNLvfGTeEIA:10 a=Z1BvOZmT1TIA:10 a=MjWgaz5//csVbyNlFB2lbA==:117
Date Thu, 21 Feb 2013 15:04:19 +1000
From Phil <phil_lor@bigpond.com>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130106 Thunderbird/17.0.2
MIME-Version 1.0
To python-list@python.org
Subject Re: Read arrow keys
References <51255C8A.7090302@bigpond.com> <nad-A7CA81.19362320022013@news.gmane.org>
In-Reply-To <nad-A7CA81.19362320022013@news.gmane.org>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2146.1361436993.2939.python-list@python.org> (permalink)
Lines 67
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1361436993 news.xs4all.nl 6909 [2001:888:2000:d::a6]:59965
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:39404

Show key headers only | View raw


On 21/02/13 13:36, Ned Deily wrote:
> In article <51255C8A.7090302@bigpond.com>, Phil <phil_lor@bigpond.com>
> 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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Read arrow keys Phil <phil_lor@bigpond.com> - 2013-02-21 15:04 +1000

csiph-web