eightban's memo

残しておきたい記事をまとめてみました。このブログに書いてあるドキュメントやブログで配布しているファイルの使用によって発生するいかなる損害に対してもこのブログの管理者は責任を負いません。使用する場合は自己責任のもとに使用してください。

AutoIt

autoit で画面の端にマウスカーソルを置いた時 または ボタンを押すと指定した場所にマウスカーソルを移動する -- CSV ファイルを読み込み,複数箇所対応,ビープ音を鳴らす

更新日:

スクリプト

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Global $_title_1 =  "mousemove2"

;[CLASS:Windows.UI.Core.CoreWindow; INSTANCE:0]
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
$mainwindow = GUICreate($_title_1, 70, 70)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$msg1="stopping"
$label1=GUICtrlCreateLabel($msg1, 10, 10)
$button1 = GUICtrlCreateButton("push", 10, 20,50, 50)
GUICtrlSetOnEvent($button1, "OKButton")
GUISetState(@SW_SHOW)

Global $Paused

Global Const $iSleep_Time=500
Const $fn = 'C:\app\autoit3\Examples\a_mousemove.txt'
Global $xx1 = 0
Global $yy1 = 0

$mm=0
Dim $Ax[1]
Dim $Ay[1]

$Ax[0]= 0
$Ay[0]= 0
HotKeySet("{Esc}", "_Exit") ; Press ESC for exit
Func _Exit()
    Exit 0
EndFunc   ;==>_Exit

HotKeySet("{F9}", "_F9")
Func _F9()
	Beep(500, 100)
	$pos = MouseGetPos()
	$Ax[0]= $pos[0]
	$Ay[0]= $pos[1]

    $Paused = NOT $Paused
    if $Paused Then
        sleep(100)
       ToolTip('cursol is "moving"',0,0)
	Else
		ToolTip("")
	EndIf
EndFunc   ;==>_Exit

$file = FileOpen($fn, 0)

;ファイルが読み込みモードで開かれたかどうかチェック
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

;EOFに達するまで1文字づつ読み込む。
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
	$mm=$mm+1

	$array2 = StringSplit($line, ",")
	_ArrayAdd($Ax, $array2[1])
	_ArrayAdd($Ay, $array2[2])

Wend
FileClose($file)

;_ArrayDelete($Ax, 0)
;_ArrayDelete($Ay, 0)

;_ArrayDisplay($Ax, "$avArray set manually 1D")

if    WinWait($_title_1, "",3) Then
		sleep(50)
    ControlClick ($_title_1,"","Button1")
	sleep(50)
	GUISetState(@SW_MINIMIZE)

EndIf


While 1
  Sleep(1000)  ; Idle around
  if $msg1="stopping"  Then
  Else
    _chk()
    _osu()
  EndIf
WEnd

Func OKButton()
;  MsgBox(0, "GUI Event", "You pressed OK!")
if $msg1="stopping"  Then
  $msg1="executing"

Else
  $msg1="stopping"
EndIf
GUICtrlSetData ($label1, $msg1)


EndFunc

Func CLOSEClicked()
 ; MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
Exit
EndFunc



;===========================
Func _chk()
	$pos1 = MouseGetPos()
	if $pos1[0]=$xx1 AND $pos1[1]=$yy1 Then
		if $pos1[0]=0 Or $pos1[1]=0  Or $pos1[0]=@DesktopWidth -1 Or $pos1[1]=@DesktopHeight-1  Then
			Beep(1500, 100)
			$Paused = NOT $Paused
			Select
               Case $pos1[0]=0
				$Ax[0]= @DesktopWidth-10
				$Ay[0]= @DesktopHeight/2
               Case $pos1[0]=@DesktopWidth -1
				$Ax[0]= 0+10
				$Ay[0]= @DesktopHeight/2
               Case $pos1[1]=0
				$Ax[0]= @DesktopWidth/2
				$Ay[0]= @DesktopHeight-10
               Case $pos1[1]=@DesktopHeight-1
				$Ax[0]= @DesktopWidth/2
				$Ay[0]= 0+10
		     Case Else
				$Ax[0]= $pos1[0]
				$Ay[0]= $pos1[1]
			EndSelect
		EndIf
	EndIf
	 $xx1 = $pos1[0]
	 $yy1 = $pos1[1]

EndFunc
Func _osu()
	if $Paused Then
		For $iy=0 To $mm Step 1

			$xx2=$Ax[$iy]
			$yy2=$Ay[$iy]

			MouseMove($xx2, $yy2)
			Sleep($iSleep_Time)
			$pos = MouseGetPos()
			;      ToolTip('Script is "Paused"'&$iy&" "&$xx2&" "&$yy2,0,0)
			if not $Paused Then
				ExitLoop
			EndIf

			if $pos[0]=$xx2 AND $pos[1]=$yy2 Then
			Else
				Beep(900, 100)

				$Paused = NOT $Paused
  ;     ToolTip('Script is "Paused"'&$xx2&" "&$yy2,0,0)
				ToolTip("")

				ExitLoop
			EndIf
		Next
	EndIf

EndFunc

説明

画面の端にカーソルを置いておくか"{F9}"キーを押すと移動します。もう一度同じキーを押すかマウスカーソルが指定した場所からずれていると止まります
起動時に最小化するには

GUISetState(@SW_MINIMIZE)

キーを変えたい場合はHotKeySet("{F9}", "_F9")

CSVファイルの見本

Const $fn = 'C:\app\autoit3\Examples\a_mousemove.txt'

1200,10
1200,360
1200,700
640,700
10,10

その他

コピペした後は下にある文字は次のように変更してください
[ [
& &
< < > >

バッチファイルの例

powershell -WindowStyle Hidden -Command "C:\app\autoit3\AutoIt3_x64.exe C:\app\autoit3\Examples\a_mousemove2.au3"

ダウンロード

画面中央対応版はこちら

http://memo.eightban.com/autoit/autoit-mousemove3

-AutoIt

Copyright© eightban's memo , 2024 All Rights Reserved Powered by STINGER.