is there any way to make keyboard input from my program. suppose my program reeives "1" from a socket. how this data can be converted to a real time keyboard hit. means when "1" would receive , the computer would think that i pressed "1" .
-
Try to look into PyWin32, stackoverflow.com/questions/11150966/…Artsiom Rudzenka– Artsiom Rudzenka2012-11-05 01:55:06 +00:00Commented Nov 5, 2012 at 1:55
-
That only works if windows is the intended target. Is it?Brian Cain– Brian Cain2012-11-05 01:57:25 +00:00Commented Nov 5, 2012 at 1:57
Add a comment
|
2 Answers
In Windows, you can use pywin32 to make a keypress. See this previous answer for a code example.
In Linux, this previous answer has you covered, using xsendkey or xsendkeycode
And for Macs, another previous answer using PyQt or wxPython.
3 Comments
arifcse10
if i want to hold a key for 1second then , what method should i use? for this purpose
Wehrdo
Which method are you using? Or what OS?
arifcse10
#python 2.7 in win7. sendkeys 0.3 import win32com.client import time import SendKeys import os from ctypes import * shell = win32com.client.Dispatch("WScript.Shell") os.startfile("E:/Projects/server-client socket/dist/test.exe") time.sleep( 3 ) shell.SendKeys('h') shell.SendKeys('4') # i want to hold the 4 key for 1 sec
Have a look at this https://github.com/SavinaRoja/PyUserInput its cross-platform control for mouse and keyboard in python
Keyboard control works on X11(linux) and Windows systems. But no mac support as of now.
from pykeyboard import PyKeyboard
k = PyKeyboard()
k.tap_key(k.numpad_keys[1], n=1) # Tap 1 on the numpad once.