Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '#if': 0.05; 'ascii': 0.07; 'repeated': 0.07; 'url:msdn': 0.07; 'api': 0.09; 'itself,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; "wouldn't": 0.11; 'better?': 0.16; 'keys.': 0.16; 'press,': 0.16; 'pressed': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'simplest': 0.16; 'url:85)': 0.16; 'wed,': 0.16; 'detect': 0.17; 'windows': 0.19; 'feb': 0.19; 'keys': 0.22; 'feature': 0.24; 'tried': 0.25; 'checking': 0.27; "doesn't": 0.28; 'header:X -Complaints-To:1': 0.28; 'record': 0.28; 'key,': 0.29; 'array': 0.29; 'stuff': 0.30; 'code': 0.31; 'anybody': 0.32; 'could': 0.32; 'url:home': 0.33; 'to:addr:python-list': 0.33; 'list': 0.35; 'doing': 0.35; "won't": 0.35; 'received:org': 0.36; 'but': 0.36; 'others.': 0.36; 'url:library': 0.36; 'should': 0.36; 'charset:us- ascii': 0.36; 'does': 0.37; 'two': 0.37; 'being': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'release': 0.39; 'url:microsoft': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'think': 0.40; 'url:aspx': 0.60; 'skip:w 30': 0.61; 'grab': 0.64; 'making': 0.64; 'url:en-us': 0.65; 'url:%1': 0.68; 'press': 0.71; '2013': 0.84; 'dennis': 0.91; 'this;': 0.91; 'hand,': 0.97 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Simulate Keyboard keypress Delay Date: Wed, 13 Feb 2013 18:39:21 -0500 Organization: > Bestiaria Support Staff < References: <79a6ab1c-d95e-45d9-ba0c-39fa68755e8c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-249-23-251.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360798778 news.xs4all.nl 6881 [2001:888:2000:d::a6]:48664 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38833 On Wed, 13 Feb 2013 11:47:36 -0800 (PST), DaGeek247 declaimed the following in gmane.comp.python.general: > I am using the windows api feature getasynckeystate() to check the status of every key pressed; like this; > > #always checking > while(True): > #iterate through list of ascii codes > for num in range(0,127): > #if ascii code key is being pressed > if win32api.GetAsyncKeyState(num): > #do stuff > Wouldn't GetKeyboardState http://msdn.microsoft.com/en-us/library/windows/desktop/ms646299%28v=vs.85%29.aspx work better? Grab all the keys at once into an array, then scan the array for status... > This works great, almost. The issue that comes up now is that every time i press a key, the code grabs two or three key presses. > > So i tried making sure that repeated keys weren't pressed repeatedly; > this works great, but It won't record stuff like 'look' or 'suffer' because it doesn't record repeated keys. So I try doing a delay instead; > this almost works, but I end recording some double keypresses, and missing others. Does anybody have any suggestions? Off hand, the simplest scheme I could think of is, when you detect a key press, you loop over it until you detect the key release -- only then do you start scanning for other keys. IOWs, you should not be triggering on the state itself, but on the change of state in both directions. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/