ガルちゃんの内容が書かれたテキストファイルから「音読さん」のサイトに自動入力し、読み上げていくpowershellスクリプト
以前作ったガルちゃんの内容が書かれたテキストファイルから「音読さん」のサイトに自動入力し、読み上げていくpowershellスクリプトを作成しました.読み込み元ファイルは以前作成したpowershellで抽出したものを使用します.自動クリックの座標は適宜変更してください.
2024.11.03 プログラムのバグを修正しました
プログラム内容
$source = @"
using System;
using System.Runtime.InteropServices;
public static class WinApi
{
[DllImport("kernel32.dll")]
public static extern bool Beep(int freq,int duration);
}
"@
Add-Type -TypeDefinition $source
Add-Type -AssemblyName System.Windows.Forms
# Windows APIの宣言
$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
$lines = Get-Content "ガルちゃんのテキスト内容が書かれたファイルが置いてあるパス\output3.txt" -Encoding UTF8
$strLength1 = 0;
for($i=0; $i -lt $lines.Count; $i++){
$str1 = ''
if($i -eq 0){
$str1 = $lines[0]
}
$line1 = $lines[$i+1]
while($line1 -ne "---"){
$str1 += $line1
if($i -lt $lines.Count){
$i++;
$line1 = $lines[$i+1]
}else{
break
}
}
Start-Sleep -Seconds 1
# 変数設定
#---A---
$x = 411
$y = 272
# マウスカーソル移動
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y)
Start-sleep -s 1
# 左クリック
$SendMouseClick::mouse_event(0x0002, 0, 0, 0, 0);
Start-sleep -s 1
$SendMouseClick::mouse_event(0x0004, 0, 0, 0, 0);
Start-Sleep -Seconds 1
[System.Windows.Forms.SendKeys]::SendWait("^a")
Start-Sleep -Seconds 1
[System.Windows.Forms.SendKeys]::SendWait("{DEL}")
Start-Sleep -Seconds 1
Set-Clipboard $str1
$strLength1 = $str1.Length
Start-Sleep -Seconds 1
# 変数設定
#---A---
$x = 411
$y = 272
# マウスカーソル移動
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y)
Start-sleep -s 1
# 左クリック
$SendMouseClick::mouse_event(0x0002, 0, 0, 0, 0);
Start-sleep -s 1
$SendMouseClick::mouse_event(0x0004, 0, 0, 0, 0);
Start-Sleep -Seconds 1
[System.Windows.Forms.SendKeys]::SendWait("^V")
Start-Sleep -Seconds 1
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
Start-Sleep -Seconds 1
# 変数設定
#---A---
$x = 411
$y = 728
# マウスカーソル移動
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y)
Start-sleep -s 1
# 左クリック
$SendMouseClick::mouse_event(0x0002, 0, 0, 0, 0);
Start-sleep -s 1
$SendMouseClick::mouse_event(0x0004, 0, 0, 0, 0);
Start-Sleep -Seconds 1
# 変数設定
#---A---
if( ($i % 2) -eq 0){
$x = 411
$y = 112
}else{
$x = 411
$y = 219
}
# マウスカーソル移動
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y)
Start-sleep -s 1
# 左クリック
$SendMouseClick::mouse_event(0x0002, 0, 0, 0, 0);
Start-sleep -s 1
$SendMouseClick::mouse_event(0x0004, 0, 0, 0, 0);
Start-Sleep -Seconds 1
# 変数設定
#---A---
$x = 411
$y = 917
# 変数設定
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y)
Start-sleep -s 1
# 左クリック
$SendMouseClick::mouse_event(0x0002, 0, 0, 0, 0);
Start-sleep -s 1
$SendMouseClick::mouse_event(0x0004, 0, 0, 0, 0);
$waitSec = [Math]::Ceiling($strLength1 * 0.165)
Start-Sleep -Seconds $waitSec
}
[WinApi]::Beep(440, 5000)
使用例