Jump to content

Define Win key + Mouse scroll as hotkey


Recommended Posts

Hello, folks!

I'm trying to define Win key + Mouse scroll (up and down) as hotkey in my script, but after a deep search in the forum, and many topics about set mouse events as hotkey, I still haven't found a solution to this specific scenario.

I tried _IsPressed internal function, and also MouseOnEvent, MouseTrapEvent and HotKeySetEx UDFs, and all of them work fairly well, but apparently just for single mouse events, and not combined like I need to (a modifier key + a mouse scroll movement).

I also read something about mouse hooks, dll call, and complex stuff like that, but my knowledge about these things is very limited, so I decided to ask here for help.

What I got so far, and is working incredibly well, is unfortunately a solution that came from the "competitor" (AutoHotKey):

WinWaitClose, ahk_class AppClass
ExitApp

#If WinActive("ahk_class AppClass")
#WheelDown::SendPlay X
#WheelUp::SendPlay Y

It took me just minutes to learn how to do this in AHK, but it's kinda sad that with all these years coding with AutoIt, I didn't get a solution as simple as this one, but I really want to do all the code inside AutoIt, if possible of course...

In case you want to know, the purpose is to use this combination of keyboard modifier + mouse scroll to change brush properties in Photoshop.

Thanks in advance,

RegiOween

Edited by RegiOween
Link to comment
Share on other sites

  • Moderators

RegiOween,

Quote

but it's kinda sad that with all these years coding with AutoIt, I didn't get a solution

I find it "kinda sad" that after having been a member here for over 10 years you could not find a solution which took me about 10 minutes to produce:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

HotKeySet("{ESC}", "_Exit")

Local $hDLL = DllOpen("user32.dll")

GUICreate("", 0, 0, 0, 0)
GUISetState()

GUIRegisterMsg($WM_MOUSEWHEEL, "_WM_MOUSEWHEEL")

While 1
    Sleep(10)
WEnd

Func _WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $lParam

    Local $iDelta = BitShift($wParam, 16) ; Mouse wheel movement
    If _IsPressed("5B", $hDLL) Then ; If Left Win pressed <<<<<<<<<<<<<<
        If $iDelta > 0 Then
            ConsoleWrite("Down" & @CRLF)
        Else
            ConsoleWrite("Up" & @CRLF)
        EndIf
    EndIf

    Return $GUI_RUNDEFMSG

EndFunc   ;==>_Scrollbars_WM_MOUSEWHEEL

Func _Exit()
    Exit
EndFunc

And not a "mouse hooks, dll call" in sight..... By the way, at the moment it only works for the left Win key - adding the right Win key I leave as "an exercise for the student", as my old maths teacher used to say.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba,

Again, sorry for my lack of knowledge, but trust me, I did a lot of reading about this subject, and didn't find a solution, or maybe the solution was right in front of me, and I didn't see it...

About your code, I don't use SciTE, so I just replaced ConsoleWrite for MsgBox, but I guess it's ok, right?

Unless I miss something, the code works, but with a big drawback: The Win key is still triggering the Start menu when I release the key, stealing the focus of the active window, and the Start menu stay open until I close it manually.

I tried messing with different values of SendKeyDelay and SendKeyDownDelay, and replace the MsgBox with an actual Send, but it seems that didn't make any difference.
Also, I tried replacing MsgBox for ToolTip, believing that could be something related to timing, but the issue is the same.

As you can see, I'm trying to make my exercise, but as I said before, I really want to keep studying in AutoIt school, despite the lessons are quite hard to solve sometimes... :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...