|
試しにと思って作ってみたのですが,Shuさんのリンク先と同じやり方でした。
でもせっかく作ったので,投稿しちゃいます。
SendInputでマウスを「その場」に動かします。実験ではスクリーンセーバーは起動しませんでした。
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Timer1.Interval = 1000
Me.Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
SendInput.SendInput(0, 0, 0, dwFlags.MOUSEEVENTF_MOVED)
End Sub
End Class
Public Module SendInput
Public Enum dwFlags As Integer
MOUSEEVENTF_MOVED = &H1
MOUSEEVENTF_LEFTDOWN = &H2
MOUSEEVENTF_LEFTUP = &H4
MOUSEEVENTF_RIGHTDOWN = &H8
MOUSEEVENTF_RIGHTUP = &H10
MOUSEEVENTF_MIDDLEDOWN = &H20
MOUSEEVENTF_MIDDLEUP = &H40
MOUSEEVENTF_WHEEL = &H80
MOUSEEVENTF_XDOWN = &H100
MOUSEEVENTF_XUP = &H200
MOUSEEVENTF_ABSOLUTE = &H8000
End Enum
Private Enum type As Integer
INPUT_MOUSE = 0
INPUT_KEYBOARD = 1
INPUT_HARDWARE = 2
End Enum
<DllImport("user32.dll")> _
Private Function SendInput( _
ByVal nInputs As Integer, _
ByRef pInputs As INPUT, _
ByVal cbSize As Integer) _
As Integer
End Function
<DllImport("user32.dll")> _
Private Function GetMessageExtraInfo() _
As IntPtr
End Function
Public Sub SendInput(ByVal dx As Integer, ByVal dy As Integer, ByVal mouseData As Integer, ByVal Flags As Integer)
Dim inputevents As New INPUT
inputevents.type = type.INPUT_MOUSE
inputevents.mi.dx = dx
inputevents.mi.dy = dy
inputevents.mi.mouseData = mouseData
inputevents.mi.dwFlags = Flags
inputevents.mi.time = 0
inputevents.mi.dwExtraInfo = GetMessageExtraInfo()
SendInput(1, inputevents, Marshal.SizeOf(inputevents))
End Sub
<StructLayout(LayoutKind.Explicit)> _
Private Structure INPUT
<FieldOffset(0)> Dim type As Integer
<FieldOffset(4)> Dim mi As MOUSEINPUT
End Structure
<StructLayout(LayoutKind.Explicit)> _
Private Structure MOUSEINPUT
<FieldOffset(0)> Public dx As Integer
<FieldOffset(4)> Public dy As Integer
<FieldOffset(8)> Public mouseData As Integer
<FieldOffset(12)> Public dwFlags As Integer
<FieldOffset(16)> Public time As Integer
<FieldOffset(20)> Public dwExtraInfo As IntPtr
End Structure
End Module
|