top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to simulate keydown and keyup events using win32api in python?

+2 votes
630 views
win32api.keybd_event(code,0,0,0)
time.sleep(2)
win32api.keybd_event(code,0,win32con.KEYEVENTF_KEYUP,0)

Above code is simulating single click on button but not press Key Hold but I want to hold the until key up event is called
eg: for key 'a' down it have to simulate key continous set until keyUp is called but not like "a"

Please specify any python API to simulate continues keyDown until it receives keyUp event

posted Aug 6, 2015 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
+1 vote

I am trying to understand how to use named pipes in python to launch external processes (in a Linux environment).

As an example I am trying to "imitate" the behaviour of the following sets of commands is bash:

> mkfifo named_pipe
> ls -lah > named_pipe &
> cat < named_pipe

In Python I have tried the following commands:

import os
import subprocess as sp

os.mkfifo("named_pipe",0777) #equivalent to mkfifo in bash..
fw = open("named_pipe",'w')
#at this point the system hangs...

My idea it was to use subprocess.Popen and redirect stdout to fw... next open named_pipe for reading and giving it as input to cat (still using Popen).

I know it is a simple (and rather stupid) example, but I can't manage to make it work..

How would you implement such simple scenario?

0 votes

I want to monitor printers for events such as the completion of printing. If the printer initiates an SNMP trap event when the job has finished printing, how can I capture this?

Presumably I need some sort of deamon to listen for these trap messages. I have looked at pySNMP but am not sure if this can be used to capture SNMP trap events from the printer.

+2 votes

I wanna simulate C style integer division in Python3.

So far what I've got is:

# a, b = 3, 4

import math
result = float(a) / b
if result > 0:
 result = math.floor(result)
else:
 result = math.ceil(result)

I found it's too laborious. Any quick way?

+1 vote

Let's say I want to compare two csv files: file A and file B. They are both similarly built - the first column has product IDs (one product per row) and the columns provide some stats about the products such as sales in # and $.

I want to compare these files - see which product IDs appear in the first column of file A and not in B, and which in B and not A.
Finally, it would be very great if the result could be written into two new CSV files - one product ID per row in the first column. (no other data in the other columns needed)

This is the script I tried:

import csv

#open CSV's and read first column with product IDs into variables pointing to lists
A = [line.split(',')[0] for line in open('Afile.csv')]
B = [line.split(',')[0] for line in open('Bfile.csv')]

#create variables pointing to lists with unique product IDs in A and B respectively 
inAnotB = list(set(A)-set(B))
inBnotA = list(set(B)-set(A))

print inAnotB
print inBnotA

c = csv.writer(open("inAnotB.csv", "wb"))
c.writerow([inAnotB])

d = csv.writer(open("inBnotA.csv", "wb"))
d.writerow([inBnotA])

print "done!" 

But it doesn't produce the required results.
It prints IDs in this format:

247158132n

and nothing to the csv files.

0 votes

Please give me some idea about how we can query the DNS
How you have divided the passive dns functioning into two parts as recursor and resolver.
Can you please give some idea about how they function, and when they are employed after the query is submitted to the pdns
How the data packet will be analyzed for ddos attack.

...