首页 > 系统服务 > 详细

Powershell mouse_event

时间:2021-08-04 22:31:21      阅读:39      评论:0      收藏:0      [点我收藏+]

No worries for your PC being idle during the office time. This Powershell down below will help you:

 

* Tips: First time when running the PowerShell

Run command  : Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

Then put :   Y

技术分享图片

 

 

 

 

Step1: Create a file named:   Click-MouseButton.ps1

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, 0, 0, 0);
        $SendMouseClick::mouse_event(0x00000004, 0, 0, 0, 0);
    }
    if($Button -eq "right")
    {
        $SendMouseClick::mouse_event(0x00000008, 0, 0, 0, 0);
        $SendMouseClick::mouse_event(0x00000010, 0, 0, 0, 0);
    }
    if($Button -eq "middle")
    {
        $SendMouseClick::mouse_event(0x00000020, 0, 0, 0, 0);
        $SendMouseClick::mouse_event(0x00000040, 0, 0, 0, 0);
    }

}
}
while ($true){
    Sleep 3     <#Delay for 3 seconds#> 
    Click-MouseButton  "left"     <# left click #> 
}

 

Step2:

技术分享图片

 

 

 

Result :

技术分享图片

 

Powershell mouse_event

原文:https://www.cnblogs.com/tangh4/p/15100875.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!