最近要對一個 Windows 程序寫 UI 測試,才發現寫 UI 測試是多麼的麻煩。發消息倒可以用 PostMessage ,但模擬按鍵就另當別論了,用 PostMessage 根本不起作用。
後來找到了這篇文章:You can't simulate keyboard input with PostMessage:http://blogs.msdn.com/b/oldnewthing/archive/2005/05/30/423202.aspx 。得出的結論是使用 SendInput() 函數。
下面是我的代碼:
PS. 又想起 AutoHotKey 裏的 SendInput ,原來這名字是這麼來的!