Skip to content

Instantly share code, notes, and snippets.

@hdemon
Created June 25, 2013 14:15
Show Gist options
  • Save hdemon/5858774 to your computer and use it in GitHub Desktop.
Save hdemon/5858774 to your computer and use it in GitHub Desktop.
yukari automation
# encoding: shift_jis
require 'Win32API'
require 'win32ole'
SW_HIDE = 0 #ウィンドウを隠して他のウィンドウにフォーカス
SW_SHOWNORMAL = 1 #通常サイズで表示しフォーカスをあたえる
SW_SHOWMINIMIZED = 2 #最小化状態で表示しフォーカスをあたえる
SW_SHOWMAXIMIZED = 3 #最大化状態で表示しフォーカスをあたえる
SW_SHOWNOACTIVATE = 4 #通常サイズで表示するがフォーカスはなし
SW_SHOW = 5 #通常サイズで表示しフォーカスをあたえる
SW_MINIMIZE = 6 #最小化状態で表示し、Z オーダーが次のトップレベルウィンドウにフォーカス
SW_SHOWMINNOACTIVE = 7 #アイコン化して表示してフォーカスはなし
SW_SHOWNA = 8 #現在のサイズで表示するが、フォーカスはなし
SW_RESTORE = 9 #=SW_SHOWNORMAL
SW_SHOWDEFAULT = 10 #CreateProcessのパラメータとおりに表示
# SW_FORCEMINIMIZE #ウィンドウを所有するスレッドがハングしていても、ウィンドウを最小化
#(win2000以降)
# SW_NORMAL = SW_SHOWNORMAL
# SW_MAXIMIZE = SW_SHOWMAXIMIZED
# SW_MAX = SW_SHOWNOACTIVATE
FindWindow = Win32API.new("user32","FindWindow","pp","i")
FindWindowEx = Win32API.new("user32","FindWindowEx","iipp", "i")
SendMessage = Win32API.new('user32', 'SendMessage', ["L","L","L","L"],"L")
PostMessage = Win32API.new('user32', 'PostMessage', ["L","L","L","L"],"L")
ShowWindow = Win32API.new('user32', 'ShowWindow', "ii")
SetForegroundWindow = Win32API.new('user32', 'SetForegroundWindow', "i")
class YukariWindow
def initialize
@handle_top = FindWindow.call("TkTopLevel", "VOICEROID+ 結月ゆかり")
@handle_second = FindWindowEx.call(@handle_top, 0, "TkChild", "")
@handle_third = FindWindowEx.call(@handle_second, 0, "TkChild", "")
@handle_buttons = FindWindowEx.call(@handle_second, @handle_third, "TkChild", "")
# get buttons handle
@handle_registor_word_button = FindWindowEx.call(@handle_buttons, 0, "Button", "")
@handle_phrase_adjust_button = FindWindowEx.call(@handle_buttons, @handle_registor_word_button, "Button", "")
@handle_save_button = FindWindowEx.call(@handle_buttons, @handle_phrase_adjust_button, "Button", "")
@handle_stop_button = FindWindowEx.call(@handle_buttons, @handle_save_button, "Button", "")
@handle_play_button = FindWindowEx.call(@handle_buttons, @handle_stop_button, "Button", "")
# get text area
end
def activate
ShowWindow.call @handle_top, SW_SHOWNORMAL
SetForegroundWindow.call @handle_top
end
def push_save_button
PostMessage.call(@handle_save_button, 0, 0, 0)
end
def push_play_button
PostMessage.call(@handle_play_button, 0, 0, 0)
end
def paste_text_to_textarea
PostMessage.call(@handle_play_button, 0, 0, 0)
end
end
class YukariSaveDialog
attr_reader :handle_save_button
attr_reader :handle_cancel_button
def initialize
# Class蜷阪′"#32770"縺ァ縲∽ク€隕玖オキ蜍墓ッ弱↓螟牙喧縺励◎縺・□縺後€∝崋螳壹・讒伜ュ舌€・
puts @handle_top = FindWindow.call("#32770", "音声ファイルの保存")
puts @handle_submit_button = FindWindowEx.call(@handle_top, 0, "Button", "保存(&S)")
puts @handle_cancel_button = FindWindowEx.call(@handle_top, @handle_save_button || 0, "Button", "キャンセル")
end
def push_submit_button
PostMessage.call(@handle_submit_button, 0, 0, 0)
end
def push_cancel_button
PostMessage.call(@handle_cancel_button, 0, 0, 0)
end
end
wsh = WIN32OLE.new("Wscript.Shell")
itx = WIN32OLE.new("AutoITX3.Control")
puts itx.ClipGet # クリップボードのデータを取得
yukari = YukariWindow.new
ysd = YukariSaveDialog.new
yukari.activate
wsh.AppActivate("Ajax")
itx.ClipPut(ARGV[0]) # クリップボードにデータを設定
sleep 1
wsh.SendKeys("^a")
wsh.SendKeys("{DELETE}")
wsh.SendKeys("^v")
yukari.push_play_button
# yukari.push_save_button
# itx.ClipPut("abc") # クリップボードにデータを設定
#wsh.SendKeys("{ENTER}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment