1

I have two questions, they are aiming on same program but I made them separate... First question:

I was wondering if it's possible to catch certain keyboard input in Python, if user is not in terminal/shell. So basically, it's like this:

User opens program.pyc
User minimizes program.pyc shell
Opens up another program
Hits defined keyboard key (let's say it's "U")
Python does things from question 2

Second question:

After doing everything from first question, I'd like to use python to use few keyboard buttons in pre-defined row.It's not that hard to make row and other things, but I don't know how to force python to use keyboard keys (for example, 1, 2, 3, 4, then it stops) P.S. have on mind that shell is minimized...

Thanks for reading this, best regards, Amar!

Amar Kalabić
  • 888
  • 4
  • 15
  • 33
  • you need `pywin32` for this in Windows or utelize the `/dev/input/..` feature in Linux. – Torxed Feb 18 '14 at 11:03
  • possible duplicate of [read raw input from keyboard in python](http://stackoverflow.com/questions/16547486/read-raw-input-from-keyboard-in-python) – Torxed Feb 18 '14 at 11:04
  • @Torxed I'm not sure this is same thing. Because there's only example for linux (I want it for Windows) and as far as I understand this code, it works only if shell is opened, right? Correct me if not. Some code examples would be great. Thanks for answering.. – Amar Kalabić Feb 18 '14 at 12:03
  • 2
    Then you need pywin32 (http://sourceforge.net/projects/pywin32/) in order to achieve this. Because Windows will not deliver key-presses to applications via the normal route (DirectX/OpenGL), only active windows will recieve event data from most operating systems, and you would need to hook into the kernel of the OS in order to retrieve key-presses manually. This is why it's a bit more trickier than just creating a basic example application to end up with a key-logger. Because that's essentially what you'll have to do, a key-logger :) – Torxed Feb 18 '14 at 12:07
  • @Torxed Thanks for your help. I just installed pywin32 and pyhook and made it! It works like a charm, only thing I don't know is second question. How do I do that? – Amar Kalabić Feb 18 '14 at 12:32
  • Have a look at http://stackoverflow.com/questions/11906925/python-simulate-keydown – Torxed Feb 18 '14 at 13:11
  • @Torxed Can you give me an idea how to make this same work in linux? – Ubdus Samad May 26 '17 at 03:32

0 Answers0