加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

powershell – power shell:如何发送鼠标中键?

发布时间:2020-12-16 01:51:40 所属栏目:安全 来源:网络整理
导读:如何使用电源 shell脚本发送鼠标中键? 我想要这样的东西: Add-Type -AssemblyName System.Windows.Forms[Windows.Forms.SendKeys]::SendWait('{MButton}') 解决方法 function Click-MouseButton{param([string]$Button,[switch]$help)$HelpInfo = @'Functi
如何使用电源 shell脚本发送鼠标中键?
我想要这样的东西:

Add-Type -AssemblyName System.Windows.Forms
[Windows.Forms.SendKeys]::SendWait('{MButton}')

解决方法

function Click-MouseButton
{
param(
[string]$Button,[switch]$help)
$HelpInfo = @'

Function : Click-MouseButton
By       : John Bartels
Date     : 12/16/2012 
Purpose  : Clicks the Specified Mouse Button
Usage    : Click-MouseButton [-Help][-Button x]
           where      
                  -Help         displays this help
                  -Button       specify the Button You Wish to Click {left,middle,right}

'@ 

if ($help -or (!$Button))
{
    write-host $HelpInfo
    return
}
else
{
    $signature=@' 
      [DllImport("user32.dll",CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]
      public static extern void mouse_event(long dwFlags,long dx,long dy,long cButtons,long dwExtraInfo);
'@ 

    $SendMouseClick = Add-Type -memberDefinition $signature -name "Win32MouseEventNew" -namespace Win32Functions -passThru 
    if($Button -eq "left")
    {
        $SendMouseClick::mouse_event(0x00000002,0);
        $SendMouseClick::mouse_event(0x00000004,0);
    }
    if($Button -eq "right")
    {
        $SendMouseClick::mouse_event(0x00000008,0);
        $SendMouseClick::mouse_event(0x00000010,0);
    }
    if($Button -eq "middle")
    {
        $SendMouseClick::mouse_event(0x00000020,0);
        $SendMouseClick::mouse_event(0x00000040,0);
    }

}


}

您可以将此功能添加到您的配置文件或其他脚本,然后您可以使用以下命令调用它:

Click-MouseButton“middle”

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读