java 调用dll 方法 postmessage实现后台模拟按键_VBS调用windows api函数(postmessage)实现后台发送按键脚本...

这篇博客介绍了如何使用VBScript和Windows API函数PostMessage来实现后台模拟按键操作。通过创建对象并注册DLL,博主展示了如何找到特定窗口句柄,并发送WM_KEYDOWN消息来模拟按下F1和1002键的序列。
摘要由CSDN通过智能技术生成

'==========================================================================

'

' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0

'

' NAME:

'

' AUTHOR: Microsoft , Microsoft

' DATE : 2014/8/10

'

' COMMENT:

'

'===================定义变量,注册API对象==================================

Dim UserWrap,hWnd

Set UserWrap = CreateObject("DynamicWrapper")

Set ws=WScript.CreateObject("wscript.shell")

WScript.Sleep 500

ws.Run "calc",0

WScript.Sleep 500

'Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

UserWrap.Register "USER32.DLL", "ShowWindow", "I=hl", "f=s", "R=l"

'Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

UserWrap.Register "USER32.DLL", "FindWindow", "I=ss", "f=s", "R=l"

'Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

UserWrap.Register "USER32.DLL", "SetWindowPos", "I=Hllllll", "f=s", "R=l"

'Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)

UserWrap.Register "USER32.DLL", "PostMessage", "I=hlls", "f=s", "R=l"

'Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long

UserWrap.Register "USER32.DLL", "SetWindowText", "I=Hs", "f=s", "R=l"

'Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

UserWrap.Register "USER32.DLL", "FindWindowEx", "I=llss", "f=s", "R=l"

'Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long

UserWrap.Register "USER32.DLL", "SetCursorPos", "I=ll", "f=s", "R=l"

'===================查找控件或者窗体句柄===============================

hWnd = UserWrap.FindWindow(vbNullString,"计算器")

'hWnd = UserWrap.FindWindow("kugou_ui",vbNullString)

hWnd1 = UserWrap.FindWindowEx(hWnd,0,vbNullString,Edit)

'UserWrap.ShowWindow hWnd,SW_HIDE

'UserWrap.SetWindowText hWnd,"hello world"

' MsgBox hWnd

' MsgBox hWnd1

'UserWrap.SetWindowPos hWnd, -1, 0, 0, 0, 0, 3

'MsgBox "将鼠标移到左上角"

'UserWrap.SetCursorPos 0,0

'=================定义系统常量===========================

Private Const WM_KEYDOWN = &H100

Private Const wm_keyup= &H101

Private Const WM_CHAR = &H102

Public Const WM_SYSKEYDOWN = &H104

Public Const WM_SYSKEYUP = &H105

'=================发送F1按键=====================

UserWrap.PostMessage hWnd, WM_KEYDOWN, 112, 0

'=================发送1002========================

UserWrap.PostMessage hWnd,WM_KEYDOWN ,97,0

UserWrap.PostMessage hWnd,WM_KEYDOWN ,96,0

UserWrap.PostMessage hWnd,WM_KEYDOWN ,96,0

UserWrap.PostMessage hWnd,WM_KEYDOWN ,98,0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值