2013-02-24 85 views
2

我試圖製作一個持久性浮動工具欄來幫助我在Windows平板電腦(無鍵盤)上執行常見任務,例如'撤消','複製'和'刪除」。 現在我有這樣的:想單擊按鈕時產生按鍵

Gui, Destroy 
Gui,+AlwaysOnTop 
Gui,+ToolWindow 
Gui,+Border 
Gui, Add, Button, y5 w60, &Undo 
Gui, Add, Button, y5 w60, &Delete 
Gui, Add, Button, y8 h18, X 
Gui, Show, y0 
Return 

ButtonUndo: 
ControlSend,, ^z 
Return 

ButtonDelete: 
ControlSend,, {Backspace} 
Return 

ButtonX: 
ButtonCancel: 
Gui, Destroy 
ExitApp 

End: 
Reload 
Return 

,但它似乎並沒有做不是讓錯誤的聲音,當我點擊按鈕的任何其他。我是否需要先告訴它先關注另一個窗口?

回答

0

我真的很喜歡這個主意!問題是,只要您點擊其中一個按鈕,焦點就會從您要控制的應用程序中被移除... 因此您將命令發送到您自己的AutoHotKey應用程序中...

一個簡單解決這個問題的方法是首先發送一個Alt + Esc然後例如一個20毫秒的睡眠,發送你的命令。

ButtonUndo: 
    Send, !{Esc} ; Changed from Alt+Tab 
    Sleep, 20 
    Send, ^z 
Return 
+0

切換的例子就這樣結束了發送工作,,到位ControlSend的,, 唯一的問題是我唯一可以打開一個窗口在同一時間因爲它是有用的。我會看看我是否不能使用WinExist函數來忽略包含按鈕的窗口 – BFSmasher 2013-02-24 20:42:08

+0

爲什麼只能打開一個窗口? Alt + Tab(在Windows 7中設置好的舊XP樣式)將您切換回前一個活動應用程序。我測試了大約10個窗口。 – 2013-02-25 05:42:05

+0

winactivate的問題在於,您需要知道上一個窗口的ID,在按下按鈕時您無法獲得該窗口的ID。您可以使用settimer循環... – 2013-02-25 05:44:06

0

這裏是與SetTimer的

SetTimer, CheckWin, 100; Put at the beginning of your script 

CheckWin: 
WinGetTitle, CurrName, A 
if (CurrName = PrevName) ; check if window has been changed 
    Return ; Only continue if an other application was activated 
LastName = %PrevName% ; Use %LastName% in winactivate 
PrevName = %CurrName% ; When new app, then sync AppName and PrevName 
Return 
+0

檢查我的建議,首先使用Alt + Esc,這也適用於我的機器,並且可能比腳本不斷監視窗口更改的工作更好更快。 – 2013-02-25 09:20:12