0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cscの作法 その650

0
Posted at

概要

cscの作法、調べてみた。
Neo.IronLua、見つけたので、やってみた。
luaから電卓を操作する。

サンプルコード

using System;
using System.Diagnostics;
using System.Threading;
using Neo.IronLua;

class Program {
	static void Main() {
		var loadForms = typeof(System.Windows.Forms.SendKeys).FullName;
		var loadDiagnostics = typeof(Process).FullName;
		using (Lua lua = new Lua())
		{
			LuaGlobal global = lua.CreateEnvironment();
			global.DoChunk("calculator_macro.lua");
		}
	}
}

luaコード


-- 1. 必要な.NETの名前空間をインポート

local Process = clr.System.Diagnostics.Process
local Thread = clr.System.Threading.Thread
local SendKeys = clr.System.Windows.Forms.SendKeys

print("Windowsの電卓を起動します...")

-- 2. 電卓アプリ(calc.exe)を起動
local calcProcess = Process:Start("calc.exe")

-- 電卓が完全に起動してウィンドウが表示されるまで少し待つ(2秒)
Thread:Sleep(2000)

print("電卓の自動操作を開始します(5 + 7 = を計算)")

-- 3. SendKeysを使ってキー入力を送信
-- ※メソッドを呼ぶときはコロン「:」を使用します
SendKeys:SendWait("5")
Thread:Sleep(200) -- 人間が操作しているようなウェイト(任意)

SendKeys:SendWait("{+}") -- 「+」などの特殊文字は中括弧で囲む
Thread:Sleep(200)

SendKeys:SendWait("7")
Thread:Sleep(200)

SendKeys:SendWait("{=}") -- 「=」または「~」(Enter)で結果を出力
print("計算が完了しました。")


写真

image.png

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?