pywin32 实现寻找窗体并模拟按键
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 实现寻找窗体并模拟按键的更多相关文章
- 使用WinAPI全局热键注册和全局模拟按键
一.全局热键注册 1.先引用DLL [System.Runtime.InteropServices.DllImport("user32.dll")] //导入WinAPI publ ...
- Android随笔之——模拟按键操作的几种方式
前几天转过一篇Android上模拟按键操作.触屏事件的博客,昨天又去找了百度.谷歌了一下,写了一点简单的测试代码,留待不时之需.有需要看之前转载的那篇博客的请看这里→_→转:Android随笔之——使 ...
- delphi 向其他程序发送模拟按键
向其他程序发送模拟按键: 1.用keybd_event: varh : THandle;beginh := FindWindow('TFitForm', '1stOpt - [Untitled1]') ...
- android 模拟按键事件
模拟按键事件可以提高代码的复用性,比如在一个edittext的回车事件里做的一些处理 在该edittext的另一个输入要做相同的处理时,模拟按键事件就非常方便了. 代码很简单,直接上代码: new T ...
- android 实现模拟按键
android 实现模拟按键方法一 通过Runtime实现,代码如下: try { String keyCommand = "input keyevent " + KeyEvent ...
- C#获取窗口,模拟按键操作
C#获取窗口,模拟按键操作,实现计算器模拟操作.首先引用. using System.Runtime.InteropServices; 使用DllImport引入两个函数: // Get a hand ...
- Unity 实现模拟按键
一直在想,使用模拟按键,也可以实现一些AI操作,具体还没做过,这里使用user32.dll在unity里写的一个简单demo using UnityEngine; using System.Colle ...
- adb命令模拟按键输入keycode
adb命令模拟按键输入keycode 2017年05月18日 14:57:32 阅读数:1883 例子: //这条命令相当于按了设备的Backkey键 adb shell input keyevent ...
- linux下如何模拟按键输入和模拟鼠标【转】
转自:http://www.cnblogs.com/leaven/archive/2010/11/30/1891947.html 查看/dev/input/eventX是什么类型的事件, cat /p ...
- C#驱动级模拟按键操作
C#驱动级模拟按键操作 2013-09-26 03:17 ·AB叔 447 3 <- 点击左侧的数字“攒”一个吧 昨天遇到一个程序自动输入财付通密码的任务. 因为财付通密码控件是有安全保护的,所 ...
随机推荐
- 【辅助工具】IDEA使用
IDEA使用 快捷键 快捷键 alt+enter:代码错误智能提示 alt+up:上个方法 alt+down:下个方法 alt+1:快速定位到项目窗口,还可边按键盘输文件名查找文件 alt+F7:定位 ...
- shell 脚本之一键部署安装 Nginx
今天咸鱼给大家分享个源码编译安装 Nginx 的 shell 脚本 这个 shell 脚本可重复执行 完整源码放在最后 定义一个变量来存放 nginx 版本号 version=1.15.4 nginx ...
- docker 容器关闭与springboot/springcloud client关闭
问题的提出: 在docker容器中运行springboot.springcloud client,如何进行优雅的关闭,防止eureka出现: EMERGENCY! EUREKA MAY BE INCO ...
- AtCoder Beginner Contest 187 题解
A - Large Digits 按要求求出两个数的每位之和,进行比较即可. 时间复杂度 \(\mathcal{O}(\log(AB))\). B - Gentle Pairs 枚举所有点对求斜率. ...
- Intellij IDEA安装与配置教程(Windows版)
Intellij IDEA(简称IDEA)是Java语言的集成开发环境,在业界公认为是一款优秀的Java开发工具.分为Community社区版(免费)和Untimate终极版(付费). IDEA是一款 ...
- warning: LF will be replaced by CRLF in public/tinymce/langs/zh_CN.js
windows使用git时出现:warning:LF will be replaced by CRLF windows中的换行符为 CRLF, 而在linux下的换行符为LF,所以在执行add . 时 ...
- vue-cli3.x中public和assets的区别
今天开发了一个html5视频播放功能. vedio.mp4资源放在public文件夹下.那vue-cli3.x中public和assets的区别 vue-cli3.0有两个放置静态资源的目录分别是pu ...
- Makefile中的+=、:=、?=
1.= "="是最普通的等号,然而在Makefile中确实最容易搞错的赋值等号,使用"="进行赋值,变量的值是整个makefile中最后被指定的值.不太容易理解 ...
- CSS - checkbox 样式
.checkbox-wrap{ position:relative } .checkbox-wrap::before{ content: ''; position: absolute; top: 31 ...
- [转帖]【我和CloudQuery 的故事】安装部署CloudQuery 初体验—-前篇
https://www.modb.pro/db/1694256553947910144 一.前言 在日常数据库运维中,为连接多种数据库,经常要安装不同的客户端,非常繁琐,且占用大量存储空间.如果能有一 ...