How to Send a hotkey in AHK after raising the finger on the key, not immediately just pressing it(LCtrl & RAlt)(<^>!)?

huangapple go评论40阅读模式
英文:

How to Send a hotkey in AHK after raising the finger on the key, not immediately just pressing it(LCtrl & RAlt)(<^>!)?

问题

Sure, here are the translated parts:

; 这是将计算机设置为睡眠模式的“1”热键:
&lt;^&gt;!F8::DllCall(&quot;PowrProf\SetSuspendState&quot;, &quot;Int&quot;, 0, &quot;Int&quot;, 1, &quot;Int&quot;, 0)&#160;

; 这是在浏览器中返回到上一页的“2”热键:
#If WinActive(&quot;ahk_exe msedge.exe&quot;)
LCtrl &amp; RAlt::send, !{Left} ;&#160; &#160;
#If

- 当我在浏览器(“Microsoft Edge”)中按“1”时,只发送“2”然后才发送“1”,而“1”命令没有被发送,注意“1”在PC的任何地方都可以工作,除了在浏览器中。
- 我想要通过“1”将计算机置于睡眠模式,而不退出浏览器或最小化它,也不更改热键。
- 有没有解决方案可以做到这一点?例如(在释放按键后发送热键)
- 我尝试了这个,但没有效果:

#If WinActive("ahk_exe msedge.exe")
^Numpad1::send, !{Left}
LControl & RAlt::send ^{numpad1}
#If

- 有没有帮助来实现这个?提前感谢。

- 我注意到当按住键时,它只删除一个单词,而不是完全删除到末尾,就像按原始键(Ctrl &amp; BackSpase)的情况一样。
- 可以改进删除过程,使其与原始热键按键相同吗?

I've provided the translations of the code and the user's questions.

英文:
    ; this is the &quot;1&quot; hotkey to put PC to sleep :
    &lt;^&gt;!F8::DllCall(&quot;PowrProf\SetSuspendState&quot;, &quot;Int&quot;, 0, &quot;Int&quot;, 1, &quot;Int&quot;, 0)&#160;

    ; this is the &quot;2&quot; hotkey to go to a previous page in the browser :
    #If WinActive(&quot;ahk_exe msedge.exe&quot;)
    LCtrl &amp; RAlt::send, !{Left} ;&#160; &#160;
    #If
  • When I use a browser ("Microsoft Edge") and press the "1", only the "2" is sent before the "1" And the "1" command is not sent , note that "1" works anywhere in the PC except in the browser.
  • I would like to put the computer into sleep mode by "1" without exiting the browser or minimizing it, and without changing hotkeys.
  • Is there a solution to do that? for example (send a Hotkey after lifting a finger from the key)
  • I've tied this, but nor working :
    #If WinActive(&quot;ahk_exe msedge.exe&quot;)
    ^Numpad1::send,&#160;!{Left}
    LControl &amp; RAlt::send ^{numpad1}
    #If
  • Any help to do that? thanks in advance.

  • I noticed that when pressing and hold the key, it deletes only one word and does not complete the deletion to the end, as in the case of pressing the original key(Ctrl & BackSpase)

  • Can the deletion process be improved so that it is the same as the original Hotkey press?

答案1

得分: 1

The #If(Win) directive is evaluated as soon as the hotkey is active or whenever the program needs to know whether the hotkey is active. Therefore it is not recommended to use hotkeys that are part of other hotkeys within it. Otherwise you have to repeat commands by adding an exception.

<^>!F8::DllCall("PowrProf\SetSuspendState", "Int", 0, "Int", 1, "Int", 0)

#IfWinActive ahk_exe msedge.exe ; #If has caveats

<^RAlt Up:: If (A_PriorKey = "F8") DllCall("PowrProf\SetSuspendState", "Int", 0, "Int", 1, "Int", 0) else If (A_PriorKey = "b") send ^{BackSpace} ; to delete the previous word else send, !{Left} return

#IfWinActive

英文:

The #If(Win) directive is evaluated as soon as the hotkey is active or whenever the program needs to know whether the hotkey is active. Therefore it is not recommended to use hotkeys that are part of other hotkeys within it. Otherwise you have to repeat commands by adding an exception.

&lt;^&gt;!F8::DllCall(&quot;PowrProf\SetSuspendState&quot;, &quot;Int&quot;, 0, &quot;Int&quot;, 1, &quot;Int&quot;, 0) 

#IfWinActive ahk_exe msedge.exe ; #If has caveats

	&lt;^RAlt Up::
		If (A_PriorKey = &quot;F8&quot;)
			DllCall(&quot;PowrProf\SetSuspendState&quot;, &quot;Int&quot;, 0, &quot;Int&quot;, 1, &quot;Int&quot;, 0)
		else
		If (A_PriorKey = &quot;b&quot;)
			send ^{BackSpace} ; to delete the previous word				
		else
			send, !{Left} 
	return

#IfWinActive

huangapple
  • 本文由 发表于 2023年5月7日 23:33:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76194829.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定