import win32api
import win32gui, win32con
import win32clipboard
import re
import time class cWindow:
def __init__(self):
self._hwnd = None def SetAsForegroundWindow(self):
win32gui.SetForegroundWindow(self._hwnd) def Maximize(self):
# 最大化
win32gui.ShowWindow(self._hwnd, win32con.SW_MAXIMIZE) def _window_enum_callback(self, hwnd, regex):
if self._hwnd is None and re.match(regex, str(win32gui.GetWindowText(hwnd))) is not None:
self._hwnd = hwnd def find_window_regex(self, regex):
self._hwnd = None
win32gui.EnumWindows(self._window_enum_callback, regex) def hide_always_on_top_windows(self):
win32gui.EnumWindows(self._window_enum_callback_hide, None) def _window_enum_callback_hide(self, hwnd, unused):
if hwnd != self._hwnd:
if win32gui.IsWindowVisible(hwnd) and win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) & win32con.WS_EX_TOPMOST:
className = win32gui.GetClassName(hwnd)
if not (className == 'Button' or className == 'Shell_TrayWnd'):
win32gui.ShowWindow(hwnd, win32con.SW_FORCEMINIMIZE) def OpenFile(self,path):
# 按下F3
win32api.keybd_event(0x72, 0, 0, 0)
win32api.keybd_event(0x72, 0, win32con.KEYEVENTF_KEYUP, 0) # 打开剪贴板
win32clipboard.OpenClipboard()
# 清空剪贴板
win32clipboard.EmptyClipboard()
# 设置剪贴板内容
win32clipboard.SetClipboardData(win32con.CF_UNICODETEXT, path)
# 获取剪贴板内容
date = win32clipboard.GetClipboardData()
print("[*] OpenFile = {}".format(date))
# 关闭剪贴板
win32clipboard.CloseClipboard()
time.sleep(0.2) # 按下ctrl+v
win32api.keybd_event(0x11, 0, 0, 0)
win32api.keybd_event(0x56, 0, 0, 0)
win32api.keybd_event(0x56, 0, win32con.KEYEVENTF_KEYUP, 0)
win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0) # 按下回车
win32api.keybd_event(0x0D, 0, 0, 0)
win32api.keybd_event(0x0D, 0, win32con.KEYEVENTF_KEYUP, 0) def deatch(self):
# 按下Ctrl+Alt+F2
win32api.keybd_event(0x11, 0, 0, 0)
win32api.keybd_event(0x12, 0, 0, 0)
win32api.keybd_event(0x71, 0, 0, 0)
win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0)
win32api.keybd_event(0x12, 0, win32con.KEYEVENTF_KEYUP, 0)
win32api.keybd_event(0x71, 0, win32con.KEYEVENTF_KEYUP, 0) # 打开调试程序
def OpenFile(path):
regex = ".*x32dbg.*"
cWindows = cWindow()
cWindows.find_window_regex(regex)
cWindows.SetAsForegroundWindow()
cWindows.SetAsForegroundWindow()
cWindows.OpenFile(path) # 关闭调试程序
def DeatchFile():
regex = ".*x32dbg.*"
cWindows = cWindow()
cWindows.find_window_regex(regex)
cWindows.SetAsForegroundWindow()
cWindows.SetAsForegroundWindow()
cWindows.deatch()

pywin32 实现寻找窗体并模拟按键的更多相关文章

  1. 使用WinAPI全局热键注册和全局模拟按键

    一.全局热键注册 1.先引用DLL [System.Runtime.InteropServices.DllImport("user32.dll")] //导入WinAPI publ ...

  2. Android随笔之——模拟按键操作的几种方式

    前几天转过一篇Android上模拟按键操作.触屏事件的博客,昨天又去找了百度.谷歌了一下,写了一点简单的测试代码,留待不时之需.有需要看之前转载的那篇博客的请看这里→_→转:Android随笔之——使 ...

  3. delphi 向其他程序发送模拟按键

    向其他程序发送模拟按键: 1.用keybd_event: varh : THandle;beginh := FindWindow('TFitForm', '1stOpt - [Untitled1]') ...

  4. android 模拟按键事件

    模拟按键事件可以提高代码的复用性,比如在一个edittext的回车事件里做的一些处理 在该edittext的另一个输入要做相同的处理时,模拟按键事件就非常方便了. 代码很简单,直接上代码: new T ...

  5. android 实现模拟按键

    android 实现模拟按键方法一 通过Runtime实现,代码如下: try { String keyCommand = "input keyevent " + KeyEvent ...

  6. C#获取窗口,模拟按键操作

    C#获取窗口,模拟按键操作,实现计算器模拟操作.首先引用. using System.Runtime.InteropServices; 使用DllImport引入两个函数: // Get a hand ...

  7. Unity 实现模拟按键

    一直在想,使用模拟按键,也可以实现一些AI操作,具体还没做过,这里使用user32.dll在unity里写的一个简单demo using UnityEngine; using System.Colle ...

  8. adb命令模拟按键输入keycode

    adb命令模拟按键输入keycode 2017年05月18日 14:57:32 阅读数:1883 例子: //这条命令相当于按了设备的Backkey键 adb shell input keyevent ...

  9. linux下如何模拟按键输入和模拟鼠标【转】

    转自:http://www.cnblogs.com/leaven/archive/2010/11/30/1891947.html 查看/dev/input/eventX是什么类型的事件, cat /p ...

  10. C#驱动级模拟按键操作

    C#驱动级模拟按键操作 2013-09-26 03:17 ·AB叔 447 3 <- 点击左侧的数字“攒”一个吧 昨天遇到一个程序自动输入财付通密码的任务. 因为财付通密码控件是有安全保护的,所 ...

随机推荐

  1. 离散化/线段树 (POJ - 2528 Mayor's posters)

    Mayor's posters https://vjudge.net/problem/POJ-2528#author=szdytom 线段树 + 离散化 讲解:https://blog.csdn.ne ...

  2. Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2) (ABCE补题记录)

    补题链接:Here 1523A. Game of Life 生命游戏定义 本题中改编为一维坐标上的生命游戏 即使 \(m(m\in[1,1e9])\) 的范围很大,但每次进化不会超过 \(n\) 次, ...

  3. vue中class样式与内联样式

    (1):style使用 <div class="score" :style="{ color: colorComputed(item.status) }" ...

  4. CF1656F Parametric MST 题解

    为了便于解题,先对 \(a\) 数组从小到大进行排序. 首先,根据定义可以得出总价值的表达式: \[\begin{aligned} W&=\sum\limits_{(u,v)\in E}[a_ ...

  5. TICK 中Kapacitor功能和使用说明

    转载请注明出处: 1.Kapacitor 简介 Kapacitor是InfluxData公司开发的一个实时流数据处理引擎.它可以实时地通过TICK脚本处理InfluxDB中的流数据以及批处理数据. K ...

  6. spring boot 中默认最大线程连接数,线程池数配置查看

    本文为博主原创,转载请注明出处: 可以查看 AbstractEndpoint  源码中的常量的定义: public abstract class AbstractEndpoint<S, U> ...

  7. 基于python+django的酒店预定网站-酒店管理系统

    该系统是基于python+django开发的酒店预定管理系统.适用场景:大学生.课程作业.毕业设计.学习过程中,如遇问题可在github给作者留言. 演示地址 前台地址: http://hotel.g ...

  8. VSCode + GCC编译器(MinGW)开发环境中文字符乱码问题踩坑与解决办法

    .markdown-body { line-height: 1.75; font-weight: 400; font-size: 16px; overflow-x: hidden; color: rg ...

  9. 【TouchGFX】MVP 示例分析

    控制流 数据流 硬按键改变View界面内容 backend --> model --> presenter --> view    View button 控制电路板LED亮灭 vi ...

  10. [转帖]Jmeter学习笔记(二十三)——生成HTML性能报告

    https://www.cnblogs.com/pachongshangdexuebi/p/11759316.html 有时候我们写性能报告的时候需要一些性能分布图,JMeter是可以生成HTML性能 ...