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 <- 点击左侧的数字“攒”一个吧 昨天遇到一个程序自动输入财付通密码的任务. 因为财付通密码控件是有安全保护的,所 ...
随机推荐
- KVM--基本管理
#!/bin/bash iso=/iso/CentOS-7-x86_64-Minimal-1708.iso #本机镜像文件位置 centos=centos7.0 #操作系统版本 disk_path=/ ...
- POJ3414 Pots( BFS搜索)
题目: 给你两个容器,分别能装下A升水和B升水,并且可以进行以下操作 FILL(i) 将第i个容器从水龙头里装满(1 ≤ i ≤ 2); DROP(i) 将第i个容器抽干 POUR(i,j) 将第i个 ...
- Codeforces Round #727 (Div. 2) A~D题题解
比赛链接:Here 1539A. Contest Start 让我们找出哪些参与者会干扰参与者i.这些是数字在 \(i+1\) 和 \(i+min(t/x,n)\)之间的参与者.所以第一个最大值 \( ...
- Educational Codeforces Round 97 (Rated for Div. 2) (A - D题个人题解)
1437A. Marketing Scheme 题意:最近猫粮店正在打折销售猫粮罐头,在给定客人能买的罐头数量区间内求合适包装大小 思路:说实话,在比赛刚开始没看懂题,最后放弃读题直接研究给出的样例解 ...
- freeswitch的2833和inband对接方案
概述 freeswitch支持三种模式的DTMF传输方式,分别时inband.INFO.2833. 在传统的PSTN网络中,所有的DTMF码都是inband模式,所以VOIP网络和PSTN网络对接中, ...
- mybatis plus 中增删改查及Wrapper的使用
本文为博主原创,未经允许不得转载: mybatis plus 通过封装 baseMapper 以及 ServiceImpl ,实现对数据库的增删改查操作,baseMapper 是我们通常所说的 da ...
- PR 调整时间线宽度
1.问题 这里的宽度太小,不好进行下一步的调整 2.解决方法 方法一 按下=可以放宽 按下-(=左边的那个键)可以缩小宽度 方法二 拖动下方的滑动条即可 方法三 按住ALT+滚轮,即可调节
- JMS微服务开发示例(六)安全退出进程
默认情况下,如果在linux,需要关闭微服务进程,请务必使用 kill -15 进程id 命令,其他命令可能会直接关闭进程,造成数据丢失. 例如,有个后台任务,执行了一半,这时候进程突然关闭了,会形成 ...
- Go-命令行参数解析
1. 解析命令行参数 程序在执行时,获取在命令行启动程序是使用的参数 命令行( Command line interface -- CLI):基于文本来查看.处理.操作计算机的界面,又被称为 终端.控 ...
- [转帖]A Quick Look at the Huawei HiSilicon Kunpeng 920 Arm Server CPU
https://www.servethehome.com/a-quick-look-huawei-hisilicon-kunpeng-920-arm-server-cpu/ Huawei Hi ...