本帖最后由 Nsqs 于 2023-8-26 05:06 编辑
- param([byte]$Key,[byte]$Shift)
- Add-Type @"
- using System;
- using System.Runtime.InteropServices;
- public class Keyboard {
- [DllImport("user32.dll")]
- private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
- Keyboard(){}
- public static void Sendkeys(byte key, byte shift = 0){
- if(shift == 0){
- keybd_event(key, 0, 0, 0);
- keybd_event(key, 0, 2, 0);
- }else{
- keybd_event(shift, 0, 0, 0);
- keybd_event(key, 0, 0, 0);
- keybd_event(key, 0, 2, 0);
- keybd_event(shift, 0, 2, 0);
- }
- }
- }
- "@;
- [Keyboard]::Sendkeys($Key,$Shift) # Ctrl=17;97=Num1
复制代码 保存为PowerShell代码
然后vbs代码- function KeyBoard(byval vkey,byval shift)
- set ws=createobject("Wscript.Shell")
- ws.run "powershell -noprofile -executionpolicy bypass -file "&chr(34)& "SendKeys.ps1"&chr(34)&chr(32)&vKey&chr(32)&Shift,0
- end function
- '使用方法<键值,组合键值>
- KeyBoard 97,17 'Ctrl=17
复制代码 与PowerShell脚本保存在同一文件夹内进行测试 |