0
私は、ウィンドウの外でキーボードのプレスを検出する必要があるプログラムを作成しています。どのように私は、次のような何かをできるようになります。キーボードのプレスを検出する
while True:
if getKey() == w:
#Do a thing
if getKey() == a:
#Do a different thing
私は、ウィンドウの外でキーボードのプレスを検出する必要があるプログラムを作成しています。どのように私は、次のような何かをできるようになります。キーボードのプレスを検出する
while True:
if getKey() == w:
#Do a thing
if getKey() == a:
#Do a different thing
「窓の外には、」実際に「コンソールの外」を意味しますが、出力ファイルにキーワードイベントを追加するには、以下のような何かを試みることができると仮定すると、 。
import win32api
import sys
import pythoncom, pyHook
buffer = ''
def OnKeyboardEvent(event):
if event.Ascii == 5:
sys.exit()
if event.Ascii != 0 or 8:
f = open ('c:\\output.txt', 'a')
keylogs = chr(event.Ascii)
if event.Ascii == 13:
keylogs = keylogs + '\n'
f.write(keylogs)
f.close()
while True:
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
http://antihackingtutorials.blogspot.de/2012/06/in-this-tutorial-we-will-show-you-how.html
あなたは(getchはを使用することができます) –
http://stackoverflow.com/questions/11918999/key-listeners-in-python – Jonas
この質問はすでにanwserを持っていません。上記の答えは、コマンドコンソールでのみ動作し、彼はプロンプトの外で作業する何かを探しています。 – Moondra