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


Groups > comp.lang.python > #38868

Re: Simulate Keyboard keypress Delay

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <SRS0=o1gJca=MG=inqvista.com=inq1ltd@eigbox.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; '#if': 0.05; 'ascii': 0.07; 'repeated': 0.07; 'api': 0.09; 'runtime': 0.09; 'keys.': 0.16; 'msvcrt': 0.16; 'pressed': 0.16; 'time.time()': 0.16; 'undo': 0.16; 'wrote:': 0.17; 'char': 0.17; 'windows': 0.19; 'module': 0.19; 'import': 0.21; 'keys': 0.22; 'machine.': 0.22; 'wednesday,': 0.22; 'cc:2**0': 0.23; '&gt;': 0.23; 'feature': 0.24; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'cc:addr:gmail.com': 0.27; 'checking': 0.27; 'c++': 0.27; "doesn't": 0.28; 'record': 0.28; 'key,': 0.29; 'stuff': 0.30; 'code': 0.31; 'anybody': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'list': 0.35; 'doing': 0.35; "won't": 0.35; 'but': 0.36; 'url:org': 0.36; 'others.': 0.36; 'received:71': 0.36; 'charset:us-ascii': 0.36; 'does': 0.37; 'url :rec-html40': 0.37; 'two': 0.37; 'being': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'received:10': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'end': 0.40; 'skip:w 30': 0.61; 'making': 0.64; 'soon': 0.70; 'press': 0.71; 'url:dtd': 0.81; '2013': 0.84; 'received:10.20.18.10': 0.84; 'received:66.96.187': 0.84; 'received:bosauthsmtp10.eigbox.net': 0.84; 'this;': 0.91; 'url:strict': 0.91
X-Authority-Analysis v=2.0 cv=FqCHDhXq c=1 sm=1 a=SOqxGZ/Bs78ttoKqqWCU3g==:17 a=spKFjZujUncA:10 a=2Cs5qbXtQ68A:10 a=QZkVo9_zR3AA:10 a=OmMKortqy18A:10 a=tTExfe6FAAAA:8 a=Ocyt8ySrg6UA:10 a=SxDny3IqAAAA:8 a=D7WcRbdHPqL-31HDOfAA:9 a=CjuIK1q_8ugA:10 a=P3uMDV8RXKwA:10 a=1p_gAtZglYvhxQ1z:21 a=DZ-LY7w9RYEFWKLu:21 a=SSmOFEACAAAA:8 a=SQQD3MrVnOpA8AatvLEA:9 a=_W_S_7VecoQA:10 a=frz4AuCg-hUA:10 a=qMDZ_Ezp4_0A:10 a=lULLg46gCGwXTHGl:21 a=K7PiMw0ju4kvMwea:21 a=hEZBTQ3lmdVW0Zh_:21 a=Kpo39fPXdbgqDwiI3/AEUA==:117
X-EN-OrigOutIP 10.20.18.10
X-EN-IMPSID 0G6w1l0070D2CUy01G6w6H
From inq1ltd <inq1ltd@inqvista.com>
To python-list@python.org
Subject Re: Simulate Keyboard keypress Delay
Date Thu, 14 Feb 2013 11:04:59 -0500
User-Agent KMail/4.7.2 (Linux/2.6.37.6-24-desktop; KDE/4.7.2; i686; ; )
In-Reply-To <79a6ab1c-d95e-45d9-ba0c-39fa68755e8c@googlegroups.com>
References <79a6ab1c-d95e-45d9-ba0c-39fa68755e8c@googlegroups.com>
MIME-Version 1.0
Content-Type multipart/alternative; boundary="nextPart36791634.cccBI1JxTx"
Content-Transfer-Encoding 7Bit
X-EN-UserInfo ea107384e720a598200e9790e8ca8002:9d89a6cbd5a73a41b134431a25286195
X-EN-AuthUser inq1ltd@inqvista.com
Sender inq1ltd <inq1ltd@inqvista.com>
X-EN-OrigIP 71.246.146.193
X-EN-OrigHost pool-71-246-146-193.rich.east.verizon.net
Cc DaGeek247 <imageek247@gmail.com>
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.1770.1360860014.2939.python-list@python.org> (permalink)
Lines 172
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360860014 news.xs4all.nl 6897 [2001:888:2000:d::a6]:48980
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38868

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Wednesday, February 13, 2013 11:47:36 AM DaGeek247 wrote:
> 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
> 
> 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;
> 
> #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):
>             if oldkeychar == num:
>                 #don't do stuff
>             else:
>                 #do stuff
> 
> 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;
> 
> #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):
>             if oldkeychar == num:
>                 if crrenttime > (time.time() - .5)
>                     #do stuff because key has been repeated, but not because
> it was held down else:
>                     #don't do stuff because key is pressed to soon
>             else:
>                 #do stuff because key is not repeated
>                 currenttime = time.time()
> 
> this almost works, but I end recording some double keypresses, and missing
> others. Does anybody have any suggestions?


this will only work on a windows machine. It is from C++ runtime lib 
msvcrt.dll


in py module 
import msvcrt

while 1:
    ch = msvcrt.getch()   ## returns one char
    if ch == 'Y' :
       # do stuff or break
        break

    print "%d (%r)"  % (ch, ch)


  # also,  kbhit()  #  returns true if char is available

  # also, ungetch(ch)  # undo char ch

jd
inqvista.com






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


Thread

Simulate Keyboard keypress Delay DaGeek247 <imageek247@gmail.com> - 2013-02-13 11:47 -0800
  Re: Simulate Keyboard keypress Delay Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-13 18:39 -0500
  Re: Simulate Keyboard keypress Delay 88888 Dihedral <dihedral88888@googlemail.com> - 2013-02-13 16:45 -0800
  Re: Simulate Keyboard keypress Delay inq1ltd <inq1ltd@inqvista.com> - 2013-02-14 11:04 -0500

csiph-web