VBS调用windows api函数(postmessage)实现后台发送按键脚本
2020-12-13 06:27
标签:os io 2014 ar cti amp log window ‘========================================================================== Set UserWrap = CreateObject("DynamicWrapper") 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 ‘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) ‘Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long ‘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 ‘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" ‘===================查找控件或者窗体句柄=============================== hWnd1 = UserWrap.FindWindowEx(hWnd,0,vbNullString,Edit) ‘UserWrap.ShowWindow hWnd,SW_HIDE ‘UserWrap.SetWindowText hWnd,"hello world" ‘ MsgBox hWnd ‘UserWrap.SetWindowPos hWnd, -1, 0, 0, 0, 0, 3 ‘MsgBox "将鼠标移到左上角" Private Const WM_KEYDOWN = &H100 ‘=================发送F1按键===================== ‘=================发送1002======================== VBS调用windows api函数(postmessage)实现后台发送按键脚本,搜素材,soscw.com VBS调用windows api函数(postmessage)实现后台发送按键脚本 标签:os io 2014 ar cti amp log window 原文地址:http://www.cnblogs.com/jinjiangongzuoshi/p/3905773.html
‘
‘ VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0
‘
‘ NAME:
‘
‘ AUTHOR: Microsoft , Microsoft
‘ DATE : 2014/8/10
‘
‘ COMMENT:
‘
‘===================定义变量,注册API对象==================================
Dim UserWrap,hWnd
Set ws=WScript.CreateObject("wscript.shell")
UserWrap.Register "USER32.DLL", "ShowWindow", "I=hl", "f=s", "R=l"
UserWrap.Register "USER32.DLL", "PostMessage", "I=hlls", "f=s", "R=l"
UserWrap.Register "USER32.DLL", "SetWindowText", "I=Hs", "f=s", "R=l"
UserWrap.Register "USER32.DLL", "FindWindowEx", "I=llss", "f=s", "R=l"
hWnd = UserWrap.FindWindow(vbNullString,"计算器")
‘hWnd = UserWrap.FindWindow("kugou_ui",vbNullString)
‘ MsgBox hWnd1
‘UserWrap.SetCursorPos 0,0
‘=================定义系统常量===========================
Private Const wm_keyup= &H101
Private Const WM_CHAR = &H102
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105
UserWrap.PostMessage hWnd, WM_KEYDOWN, 112, 0
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
文章标题:VBS调用windows api函数(postmessage)实现后台发送按键脚本
文章链接:http://soscw.com/essay/33056.html