Page 1 of 1

關於偵測按鍵  Topic is solved

Posted: 23 Dec 2017, 01:03
by SkyLife
我希望能偵測到我按下了什麼鍵且能在按下的時候執行命令,像是下面所列的,但是要把所有的按鍵都列進去會需要太多列
evilC發布的UCR有這樣的功能
https://autohotkey.com/boards/viewtopic.php?t=12249
希望有人能幫忙
能偵測鍵盤上的所有按鍵是最好的

Code: Select all

Gui, new
Gui +ToolWindow -Border
Gui, Font, S15
Gui, Add, Text, Center, 按下想要替換的按鍵
Gui, Show
Loop
{
	if getkeystate("A", "P" )
	{
	MsgBox 你按下了A
	ExitApp
	}
	if getkeystate("B", "P" )
	{
	MsgBox 你按下了B
	ExitApp
	}
}
return

Re: 關於偵測按鍵

Posted: 23 Dec 2017, 04:24
by garry
examples

Code: Select all

;- http://www.autohotkey.com/board/topic/15574-morse-find-hotkey-press-and-hold-patterns/
;- http://www.autohotkey.com/board/topic/9166-fkee3/
;- http://www.autohotkey.com/board/topic/35566-rapidhotkey/

; !n::run,notepad  ;- a hotkey example alt+n

;------- example -------
;- push F1  twice or 3*  
;- write this above the F1-key :
; 2* notepad
; 3* calc 

$F1::
   p := Morse()
   If (p = "00")
        run, notepad
   If (p = "000")
        run,calc
return

$F12::
   p := Morse()
   If (p = "00")
        msgbox, 262144, F12-Key, F12 2 * pushed,2
   If (p = "000")
        msgbox, 262144, F12-Key, F12 3 * pushed,2
return
;--------------------------------------------------

Morse(timeout = 400)
{
   tout := timeout/1000
   key := RegExReplace(A_ThisHotKey,"[\*\~\$\#\+\!\^]")
   Loop
       {
      t := A_TickCount
      KeyWait %key%
      Pattern .= A_TickCount-t > timeout
      KeyWait %key%,DT%tout%
      If (ErrorLevel)
         Return Pattern
       }
}
return
;===================================================

Re: 關於偵測按鍵

Posted: 23 Dec 2017, 05:52
by SkyLife
你給的例子並不能解決我的問題
這只能知道次數,而且我需要創建無數個熱鍵

Re: 關於偵測按鍵

Posted: 23 Dec 2017, 14:04
by garry
hotkeys ( alt+x... )

Code: Select all

!a::run,notepad
!b::run,calc
!c::run,charmap
;.....

Re: 關於偵測按鍵

Posted: 23 Dec 2017, 21:43
by SkyLife
謝謝你的回覆,我已經找到更好的方法了