请教如何实现Ctrl+C与Ctrl+C+C功能不同

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: 请教如何实现Ctrl+C与Ctrl+C+C功能不同

Re: 请教如何实现Ctrl+C与Ctrl+C+C功能不同

by AAHKUser » 28 Jun 2020, 16:43

@tmplinshi
发现现在空格也会算为字数,我做了一点点点修改,加了一行

Code: Select all

~^c::     
Clip:=StrReplace(Clipboard, A_Space, "")    ;去掉空格
	if IsDoubleClick()
		ToolTip(StrLen(Clip)" 个字",,,, 2000)
Return

IsDoubleClick() {
	static doubleClickTime := DllCall("GetDoubleClickTime")
	KeyWait, % LTrim(A_ThisHotkey, "~")
	return (A_ThisHotKey = A_PriorHotKey) && (A_TimeSincePriorHotkey <= doubleClickTime)
}

ToolTip(Text := "", X := "", Y := "", WhichToolTip := 1, Timeout := "") {
	ToolTip, % Text, X, Y, WhichToolTip

	If (Timeout) {
		RemoveToolTip := Func("ToolTip").Bind(,,, WhichToolTip)
		SetTimer, % RemoveToolTip, % -Timeout
	}
}

Re: 请教如何实现Ctrl+C与Ctrl+C+C功能不同

by AAHKUser » 28 Jun 2020, 08:17

@tmplinshi
非常感谢您的分享!功能很完美,设计的好简洁,我有些地方还看不太懂,正在对这资料看:)

Re: 请教如何实现Ctrl+C与Ctrl+C+C功能不同

by tmplinshi » 26 Jun 2020, 02:30

试试这样:

Code: Select all

~^c::
	if IsDoubleClick()
		ToolTip(StrLen(Clipboard),,,, 2000)
Return

IsDoubleClick() {
	static doubleClickTime := DllCall("GetDoubleClickTime")
	KeyWait, % LTrim(A_ThisHotkey, "~")
	return (A_ThisHotKey = A_PriorHotKey) && (A_TimeSincePriorHotkey <= doubleClickTime)
}

ToolTip(Text := "", X := "", Y := "", WhichToolTip := 1, Timeout := "") {
	ToolTip, % Text, X, Y, WhichToolTip

	If (Timeout) {
		RemoveToolTip := Func("ToolTip").Bind(,,, WhichToolTip)
		SetTimer, % RemoveToolTip, % -Timeout
	}
}

请教如何实现Ctrl+C与Ctrl+C+C功能不同

by AAHKUser » 26 Jun 2020, 01:18

我目前参考1Hour实现了按Ctrl+C统计复制的字数的功能,但我现在想实现Ctrl+C复制(单击C),只有按Ctrl+C+C才复制并显示字数(快速双击C)

目前只查到似乎可以用KeyWait或者TimeSet实现,但我写出来时灵时不灵,请教大家该如何修改,谢谢。

Code: Select all

$^c::
if (CtrlC_presses > 0) ; SetTimer 已经启动, 所以我们记录键击.
{
    CtrlC_presses += 1
    return
}
; 否则, 这是新开始系列中的首次按下. 把次数设为 1 并启动
; 计时器:
CtrlC_presses := 1
SetTimer, KeyCtrlC, -400 ; 在 400 毫秒内等待更多的键击.
return

KeyCtrlC:
if (CtrlC_presses = 1) ; 此键按下了一次.
{
    Send ^c
}
else if (CtrlC_presses = 2) ; 此键按下了两次.
{
  clip=%Clipboard%                
  numofwords=0  
  StringSplit,words,clip    
  ;words :=StrSplit(Clip)    ;
    loop  %words0%         ; words0,
    {
      If words%A_Index%<>                    
        numofwords+=1
    }
  ToolTip Word Count: %numofwords%
  Sleep 2000
  RemoveToolTip:
  ToolTip
  numofwords=0
  Return
}

; 不论触发了上面的哪个动作, 都对 count 进行重置
; 为下一个系列的按下做准备:
CtrlC_presses := 0
return

Top