修饰键映射问题求教

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: 修饰键映射问题求教

Re: 修饰键映射问题求教

Post by emacs25 » 13 Sep 2020, 04:37

tmplinshi wrote:
11 Sep 2020, 03:29

Code: Select all

; 单击 LAlt 输出空格,按住不放为 LControl
LAlt::
	KeyWait, LAlt, T0.3 ; 等待 LAlt 松开, 等待时间 0.3 秒
	if ErrorLevel { ; 超时
		LAlt::LControl
	} else {
		Send {Space}
	}
Return
再请教一个问题,根据如上代码,我在使用过程当中发现一个奇怪现象

当长按键的时候,表现没有任何问题,但是当短按键的时候,经常性的出现无响应

我以为是键盘的灵敏度出了问题,换了四个键盘,还是同样的情况

然后我把代码编译成独立Exe,使用过程还是同样的表现

想请问各位,这种情况是正常现象还是有问题,如果有问题的话,该如何去优化

Re: 修饰键映射问题求教

Post by emacs25 » 11 Sep 2020, 08:18

懂了,谢谢大神的仔细解释,再次感谢

Re: 修饰键映射问题求教

Post by tmplinshi » 11 Sep 2020, 06:52

首先, 空格的名称是 {Space}, 而不是 {SPC}
然后, 可以用 A_TimeSinceThisHotkey 来判断长按短按

Code: Select all

^r::MsgBox  Ctrl + r
^!r::MsgBox Alt + Ctrl + r

Lalt::
   Send {LControl Down}
   KeyWait, Lalt
   Send {LControl Up}
   If (A_TimeSinceThisHotkey < 300)
   {
      Send {Space}
   }
return
以上代码可以区分长按短按, 但是当你长按住alt, 再按 r, 会发现实际上触发的是 Alt + Ctrl + r, 而不是预想中的 Ctrl + r.
另外代码逻辑与你的描述也不一致. 你的描述是 "单击变空格, 长按变 ctrl", 但是代码不管长按短按都会按 ctrl

Re: 修饰键映射问题求教

Post by emacs25 » 11 Sep 2020, 05:58

感谢大神的解答,已经测试成功

另外求教我上面的代码哪里有问题呢

Re: 修饰键映射问题求教

Post by tmplinshi » 11 Sep 2020, 03:29

Code: Select all

; 单击 LAlt 输出空格,按住不放为 LControl
LAlt::
	KeyWait, LAlt, T0.3 ; 等待 LAlt 松开, 等待时间 0.3 秒
	if ErrorLevel { ; 超时
		LAlt::LControl
	} else {
		Send {Space}
	}
Return

修饰键映射问题求教

Post by emacs25 » 09 Sep 2020, 08:38

刚接触autohoktey没多久,想实现如下功能
单击Lalt输出空格,按住不放为LControl,参考网络上的代码如下:

Code: Select all

Lalt::
Send {LControl Down}
KeyWait, Lalt
Send {LControl Up}
If ( A_PriorKey = "Lalt")
{
Send {SPC}
}
return
运行结果不成功,请教各位大神,代码存在什么问题,要如何修正呢,感谢!

Top