简体   繁体   English

如何在按下键而不是在释放键时触发热键而不暴露其本机 function?

[英]How to fire a hotkey when a key is pressed rather than when it is released without exposing its native function?

What I want is to simply use the XButton1 and XButton2 of my mouse as WheelRight and WheelLeft.我想要的是简单地使用鼠标的 XButton1 和 XButton2 作为 WheelRight 和 WheelLeft。 I initially did this using:我最初是这样做的:

XButton1::WheelRight
XButton2::WheelLeft

But, I was not satisfied with this because each time I would press the XButton, it would scroll only once and that too only when the key was released.但是,我对此并不满意,因为每次我按下 XButton 时,它只会滚动一次,而且只有在释放键时才会滚动。 So I came up with this:所以我想出了这个:

~XButton2::
    Send {WheelLeft}
    Sleep, 500
    while GetKeyState("XButton2")
    {
        Send {WheelLeft}
        Sleep, 50
    }
return

Similar code can be written for XButton1.可以为 XButton1 编写类似的代码。 This works nicely, but the only issue is that the '~' exposes the native function of the XButton2 (which is 'Forward'), which I do not want.这很好用,但唯一的问题是“~”暴露了 XButton2(即“转发”)的本机 function,这是我不想要的。 (It is fired when the key is released.) I tried to disable the key from within the mouse software but that just caused the hotkey to stop working completely. (释放键时触发。)我试图从鼠标软件中禁用该键,但这只会导致热键完全停止工作。

Now, I do know that a simple workaround for this would be to map the XButtons to some rarely used keys like RShift and RCtrl, but what I want is a more elegant and direct solution to this problem.现在,我知道一个简单的解决方法是 map XButtons 到一些很少使用的键,如 RShift 和 RCtrl,但我想要的是一个更优雅和直接的解决方案来解决这个问题。 Mapping them to keys on the number pad is not an option for me either since I have uses for it, and I'd rather not have keys on my keyboard locked up solely for this.将它们映射到数字键盘上的键对我来说也不是一个选项,因为我已经使用过它,而且我宁愿不为此单独锁定键盘上的键。

Edit:编辑:

I realized that the code I wrote initially did not work as the code I wrote later on because I had other hotkeys written for XButton1 and XButton2 such as:我意识到我最初编写的代码无法像我后来编写的代码那样工作,因为我还有其他为 XButton1 和 XButton2 编写的热键,例如:

XButton2 & WheelUp::
    Send {Volume_Up}
return

When I removed these, the initial code worked as I wanted.当我删除这些时,初始代码按我的意愿工作。 I was able to come up with a workaround to keep all of my hotkeys by assigning F13 to XButton1 and F14 to XButton2 since these keys don't even exist on my keyboard.通过将 F13 分配给 XButton1 并将 F14 分配给 XButton2,我想出了一个解决方法来保留我的所有热键,因为这些键甚至不存在于我的键盘上。 I am still leaving this question open though since I haven't gotten the answer I wanted originally.我仍然悬而未决这个问题,因为我还没有得到我最初想要的答案。 (The logic is that someone in the future may answer which could help out other people later on who unlike me are unable to find any workaround.) (逻辑是,将来可能会有人回答,这可能会帮助以后与我不同的其他人无法找到任何解决方法。)

You can use the up and down events and a timer, for example:您可以使用上下事件和计时器,例如:

*XButton1::SetTimer, WheelRight, 100
*XButton2::SetTimer, WheelLeft, 100

*XButton1 Up::SetTimer, WheelRight, Off
*XButton2 Up::SetTimer, WheelLeft, Off


WheelRight()
{
    SendInput, {Blind}{WheelRight}
}

WheelLeft()
{
    SendInput, {Blind}{WheelLeft}
}

Or maybe a cleaner version:或者也许是更清洁的版本:

;In the auto execute section
WheelLeft := Func("ScrollWheel").Bind("Left")
WheelRight := Func("ScrollWheel").Bind("Right")

;...

*XButton1::SetTimer, % WheelRight, 100
*XButton2::SetTimer, % WheelLeft, 100

*XButton1 Up::SetTimer, % WheelRight, Off
*XButton2 Up::SetTimer, % WheelLeft, Off


ScrollWheel(direction)
{
    SendInput, % "{Blind}{Wheel" direction "}"
}

* (docs) is used so you can also hold down modifiers while using the key, and the blind sendmode is used so the send command doesn't remove the modifiers. * (docs)被使用,所以你也可以在使用键的同时按住修饰符,并且使用了发送模式,所以发送命令不会删除修饰符。

Adjust the timer's delay to scroll faster or slower.调整计时器的延迟以更快或更慢地滚动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM