仅长按单键执行功能,不影响短按示例

许多实用脚本和封装函数, 可以让您编写脚本更加便捷高效

Moderators: tmplinshi, arcticir

nuance
Posts: 7
Joined: 23 Jan 2015, 21:01

仅长按单键执行功能,不影响短按示例

23 Jan 2015, 21:54

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
$T::
SetTimer, mainc, 10       ;10毫秒执行一次
return

mainc:
counts ++
GetKeyState, tstt, T, P      ;获取按键T的状态
if ( tstt = "U" )   ;当松开按键的时候
{
	SetTimer, mainc, off   ;取消定时器
	if (counts < 11)   ;如果counts在10以内,说明从按下到松开的时间为10*10=100毫秒,判断为短按。
	{
		GetKeyState, capstt, CapsLock, T       ;获取大小写锁定键状态
		if ( capstt = "D" )   ;如果锁定
		{
			Send T        ;发送T
		}
		else
		{
			Send t        ;发送t
		}
	}
	else            ;如果counts大于10,说明是长按,则执行下面的主程序
	{
		MsgBox, 即将戳开百度
		gosub, mainp    ;转到mainp
	}
	counts = 0        ;重置计数,清空变量,用于下次使用
	tstt := 
	capstt := 
	return
}
return

mainp:
Run, http://www.baidu.com
return
tmplinshi
Posts: 1549
Joined: 01 Oct 2013, 14:57

Re: 仅长按单键执行功能,不影响短按示例

24 Jan 2015, 09:42

这样简单点

Code: Select all

$t::
	KeyWait, t
	If (A_TimeSinceThisHotkey > 300)
		SetTimer, mainp, -1
	Else
		SendInput, % GetKeyState("CapsLock", "T") ? "T" : "t"
Return

mainp:
	Run, http://www.baidu.com
Return
nuance
Posts: 7
Joined: 23 Jan 2015, 21:01

Re: 仅长按单键执行功能,不影响短按示例

24 Jan 2015, 22:27

tmplinshi wrote:这样简单点

Code: Select all

$t::
	KeyWait, t
	If (A_TimeSinceThisHotkey > 300)
		SetTimer, mainp, -1
	Else
		SendInput, % GetKeyState("CapsLock", "T") ? "T" : "t"
Return

mainp:
	Run, http://www.baidu.com
Return
哈,太棒了,原来还有keywait这个功能 :bravo:
我居然都没发现,到处找方法怎么实现。
keywait更省CPU啊。
cixiplc
Posts: 8
Joined: 18 Oct 2014, 15:52

Re: 仅长按单键执行功能,不影响短按示例

03 Apr 2015, 05:30

keywait 以后还是有点区别,因为原来是按键一触即发 keywait就得等释放按键后才运行
Tom2016
Posts: 1
Joined: 23 Apr 2016, 03:52

Re: 仅长按单键执行功能,不影响短按示例

23 Apr 2016, 04:06

It is not working correctly, i found it will has issue when you press w and a, the "aw" will come out

$w::
KeyWait, w
If (A_TimeSinceThisHotkey > 500)
SetTimer, mainpw, -1
Else
SendInput, % GetKeyState("CapsLock", "W") ? "W" : "w"
Return
mainpw:
msgbox, w
Return
pigwei
Posts: 10
Joined: 13 Oct 2019, 02:36

Re: 仅长按单键执行功能,不影响短按示例

13 Oct 2019, 22:04

@tmplinshi
老师 这段代码会影响打字的,其实创意很好,我很想实现,有什么办法吗

Return to “脚本函数”

Who is online

Users browsing this forum: No registered users and 3 guests