eynsai / Smooth-Trackball-Scrolling

Buttery-smooth stepless scrolling with a trackball.
MIT License
7 stars 0 forks source link

Cannot use mouse button combo as HotKey #2

Open bueny52 opened 10 months ago

bueny52 commented 10 months ago

Thank you very much for creating this script. This is the best drag scroll implementation I've used in terms of smoothness, not just among AHK scripts (the ones I found online previously were just unusable), but even when compared to e.g. XMBC. And I needed an AHK implementation because XMBC is blocked on work computer but AHK is allowed.

I'm trying to use a mouse combo of left+right click as the hotkey. For that I put ~RButton & LButton as the HotKey in the Settings. This spits out the error message,

Error: "*~RButton" is not a valid key name

and then points to line 144 as where the error happened, which is

    Hotkey, *%smoothTrackballScrollingShortcut% Up, HotkeyOff

How should I set the hotkey field to use the combination of left+right click to act as the hot key?

A somewhat unrelated issue that came up while I was trying to make the mouse button hotkey work: there is currently no way to disable the script, and no easy way to change the parameters, if/when the UI is blocked. I made the mistake of putting LButton & RButton as the first attempt of the hotkey, on top of having the script run automatically on startup. Needless to say, that freezes my mouse buttons (and movement for some reason), preventing me from accessing the UI to change it back, and since it's on startup autorun, it essentially locks up the machine. I was eventually able to kill AHK from cli (for anyone reading this and wondering, use win+r to open up cmd.exe, and then run taskkill /f /im autohotkeyu64.exe), and after that, upon reading the code, found out that the settings are stored in windows registry. I suggest adding a fail safe mechanism such as some hotkey to disable the script. Saving settings to a plain text file might also be more user-friendly under such circumstances (so I'd be able to revert the settings relatively easily with keyboard only operations).

eynsai commented 10 months ago

Thanks for your feedback!

Regarding the usage of both mouse buttons as the hotkey:

Regarding the UI blocking issue:

bueny52 commented 10 months ago

Thanks for the update, the reset.exe is useful!

  • I wrote this script with the idea of using a single keyboard key, without any modifiers, additional keys, or mouse buttons, in mind.
  • Supporting mouse buttons as hotkeys is a little scary, since the script relies on blocking mouse input during drag-scrolling, and this can lead to some edge cases that cause mouse input to get locked or blocked in really weird and wacky ways. Based on some brief testing, though, I think it should be possible.

I get where you are coming from. I'm also the living example of why having mouse button as a hot key is scary :D. On the other hand, I do believe an entirely trackball-driven work flow (independent of keyboard) is a legitimate use case. For example, in working with two computers -- each with their own trackball but only one keyboard shared between the two -- it would be useful to be able to use the script on the computer not currently connected to the keyboard. People coming from things like a Ploopy would also appreciate this kind of mouse button-driven "layer switch" (where the ball behaves differently depending on which "layer" the device is in, much like a programmable keyboard). What I'm trying to say is, the capability of having mouse button as the hotkey will bring this gem to a broader audience.

Regarding blocking mouse input, would it be possible to just block cursor motion but not button clicks? Or automatically exit the scroll mode upon certain button presses but ignore the others? Incidentally I think being able to enter and exit scroll mode with different triggers would be a useful feature (e.g., enter only on a single hotkey, but exit on a broader selection, such as Esc). Taking a page from Ploopy (or any QMK device), logically it is to implement layer switching with mouse buttons, where the behavior of both the buttons and the ball are independent between different layers (the user is responsible for having an exit strategy from higher layers back to the base layer, but the "firmware" is responsible for providing a mechanism). I suppose the difficulty is really in implementing this logic in AHK (or perhaps AHK is not adequate in that regard -- I don't really have the grasp on AHK to tell).

  • CTRL+ALT+DELETE or CTRL+SHIFT+ESC should automatically bypass AutoHotkey inside the Task Manager so that you can kill the process.

The problem I had was that the script (through my faulty hotkey setup) blocked button clicks so I was able to invoke Task Manager but cannot kill the task using mouse clicks. This of course echoes your earlier comment that using mouse buttons as hotkeys is scary.

  • I agree that using a text file for settings would be more user-friendly, but for now I'm probably too lazy to make the change. If you're comfortable with AHK, I'd welcome a pull request.

The registry thing is very minor and the reset.exe you provided would have been sufficient for the scenario that required me to go into the registry (namely to restore a clean slate). Unfortunately my knowledge of AHK stops at writing a simple keyboard remapper, but I'm definitely interested to look into it more when time permits, now that I have a motivation ;)

eynsai commented 7 months ago

It's been a while since I had time to work on this project, but I just released a new version that might address your needs in terms of mouse buttons. Not sure if you're still interested in using this script, but just thought I'd let you know.

Any feedback would be immensely appreciated!

bueny52 commented 7 months ago

Thank you! I tested one- and two-key MO with mouse buttons, and they both work very well (The one-key MO will block the original function of the assigned mouse button, which is why I also tried the two-key MO, and it works even with 2-key sym). The only thing I can think of that might potentially improve user experience is to change the mouse icon while in scroll mode, to give some visual indication.

Would it be possible to add a one-key toggle with a delay (but in a sense opposite to the hold delay currently implemented for 2-key MO)? The use case I have in mind is to toggle scrolling by holding the middle mouse button for more than, say, 500 ms. A two-key toggle would also be very useful (so it doesn't block the function of the individual keys) but I imagine there are technical difficulties.

Thanks again for the awesome work!