PDA

View Full Version : How to grab keyboard command in Python ?



prismctg
June 1st, 2012, 03:21 AM
How to grab keyboard command in Python 3.x ? I want to grab some keyboard command like ctrl+x , F9 etc in my program

hailholyghost
June 11th, 2012, 12:11 AM
I'm not sure what you mean.

If you mean when executing a python program at the command line, e.g.


$python 23

a sample script would look like:


#!/usr/bin/python
import sys
import math

i = float(sys.argv[1])
i = i/4
print i
j = float(4)/7
print j
where "sys.argv[1]" is the first argument passed to the command.

Is that what you mean?

prismctg
June 12th, 2012, 02:23 AM
no, I just want to capture keyboard command like ctrl+x in my program .example: If I press ctrl+x program do some job .

overcast
June 12th, 2012, 10:47 AM
So you want to capture hotkeys? Like say ALT or CTRL+P sort?

You can check the pykeylogger.

http://pykeylogger.wiki.sourceforge.net/