windows powershell 模拟鼠标点击click

原来公司定时播放音乐的mac mini前段时间总是死机,断电过一段时间又能开机,然后又死机,一怒之下装了windows,这下好了更新后开机屏幕不显示,重置了好几次smc和nvram(当然,这都是群里老司机告诉我的)

有人说是不是分辨率太高的原因,我想应该不是,原来osx就是1080p,后来看到有个HDMI口,死马当活马医,接到投影机上,果然显示正常了,虽然反复重启,那就继续重装

总结:windows对mac mini的mini dp口不兼容

 

装上音乐播放器,怎么定时播放呢,还是想跟原来一样定时模拟鼠标点击

原来是osx自带功能,想想windows power shell应该也有这个功能,百度一搜,看到wasp好像还不错,但是很久没更新,找不到下载链接,尴尬

好歹用了网上一个长代码,实现了,现在放上来,使用的时候只需要修改最后一行的坐标即可

保存为MouseClicketMusicstart.ps1

$cSource = @'
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class Clicker
{
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms646270(v=vs.85).aspx
[StructLayout(LayoutKind.Sequential)]
struct INPUT
{
public int type; // 0 = INPUT_MOUSE,
// 1 = INPUT_KEYBOARD
// 2 = INPUT_HARDWARE
public MOUSEINPUT mi;
}
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms646273(v=vs.85).aspx
[StructLayout(LayoutKind.Sequential)]
struct MOUSEINPUT
{
public int dx ;
public int dy ;
public int mouseData ;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}
//This covers most use cases although complex mice may have additional buttons
//There are additional constants you can use for those cases, see the msdn page
const int MOUSEEVENTF_MOVED = 0x0001 ;
const int MOUSEEVENTF_LEFTDOWN = 0x0002 ;
const int MOUSEEVENTF_LEFTUP = 0x0004 ;
const int MOUSEEVENTF_RIGHTDOWN = 0x0008 ;
const int MOUSEEVENTF_RIGHTUP = 0x0010 ;
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020 ;
const int MOUSEEVENTF_MIDDLEUP = 0x0040 ;
const int MOUSEEVENTF_WHEEL = 0x0080 ;
const int MOUSEEVENTF_XDOWN = 0x0100 ;
const int MOUSEEVENTF_XUP = 0x0200 ;
const int MOUSEEVENTF_ABSOLUTE = 0x8000 ;
const int screen_length = 0x10000 ;
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx
[System.Runtime.InteropServices.DllImport("user32.dll")]
extern static uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
public static void LeftClickAtPoint(int x, int y)
{
//Move the mouse
INPUT[] input = new INPUT[3];
input[0].mi.dx = x*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width);
input[0].mi.dy = y*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
input[0].mi.dwFlags = MOUSEEVENTF_MOVED | MOUSEEVENTF_ABSOLUTE;
//Left mouse button down
input[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
//Left mouse button up
input[2].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(3, input, Marshal.SizeOf(input[0]));
}
}
'@
Add-Type -TypeDefinition $cSource -ReferencedAssemblies System.Windows.Forms,System.Drawing
#Send a click at a specified point
[Clicker]::LeftClickAtPoint(155,650)

 

然后使用定时计划器播放

程序名:C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

参数:D:\MouseClicketMusicstop.ps1

 

直接执行脚本会出错,需执行:set-ExecutionPolicy RemoteSigned

参考链接:

https://www.cnblogs.com/zhaozhan/archive/2012/06/01/2529384.html

http://www.jb51.net/article/95022.htm

https://www.cnblogs.com/yajing-zh/p/5076545.html

posted @ 2018-05-24 13:40  邱比比  阅读(2758)  评论(0编辑  收藏  举报