How to use the wheel to scroll the menu

Get help with using AutoHotkey and its commands and hotkeys
arcticir
Posts: 647
Joined: 17 Nov 2013, 11:32

How to use the wheel to scroll the menu

23 Jul 2015, 05:54

If the menu contains many Item, open the bottom and Intermediate of the menu, it is very cumbersome and slow,
Is there any way you can use the scroll wheel, scroll through menu?
I found the Firefox Bookmarks menu can use the wheel to scroll.

Image

Code: Select all

loop 200
Menu, MyMenu, Add, Item%A_Index%, M
Menu, MyMenu, Show  
return 

M:
return
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: How to use the wheel to scroll the menu

23 Jul 2015, 13:01

you'd soon find out that once the menu is shown, there is not much you can do about it, no timers no hotkeys to be triggered, you'd have to go with something like that, http://ahkscript.org/boards/viewtopic.php?t=971
at least it triggers keyboard hotkeys, but not mouse keys as far as I can tell.
I found the Firefox Bookmarks menu can use the wheel to scroll
not the standard menu, firefox has all the control over the menu, the system doesn't interfere with its messages
arcticir
Posts: 647
Joined: 17 Nov 2013, 11:32

Re: How to use the wheel to scroll the menu

23 Jul 2015, 13:36

Yes, AHK menu commands, there many disadvantages.
So, I use the PUM.AHK, it is a great lib, Object-oriented
menu powerful.
The only drawback is that it does not scroll menus,
And the author is no longer updated.
I tried to find scroll method.
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: How to use the wheel to scroll the menu

23 Jul 2015, 20:30

have you tried to hook the mouse?
I think it may work as you want, but you'd have to see if any messages are sent to the menu window on scroll (you'd need to control everything)
Internet explorer doesn't use the scroll wheel in the context menu
zotune
Posts: 83
Joined: 17 Nov 2014, 17:57

Re: How to use the wheel to scroll the menu

24 Jul 2015, 04:05

Something like this might work :)

Code: Select all

GUI +HWNDwindowname ;Put this before your GUI

#If WinActive("ahk_id " windowname) ;Put all of this at the end of your script

WheelDown::
Send, {Down}
Return

WheelUp::
Send, {Up}
Return
arcticir
Posts: 647
Joined: 17 Nov 2013, 11:32

Re: How to use the wheel to scroll the menu

25 Jul 2015, 04:31

@MJs
我没有尝试鼠标钩子。
我想知道,WIN菜单 是不是有滚动的 API。
PUM.AHK 就是这样的脚本,但我找不到具体的代码。
I did not try the mouse hook.
I want to know, WIN menu is not a roll of API.
PUM. AHK is such a script, but I can not find the specific code.



@zotune
This is not a real roll, because {Down} will start to jump down from the top.

Thank you all.
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: How to use the wheel to scroll the menu

25 Jul 2015, 14:03

WIN menu is not a roll of API.
can you explain a little bit what you mean

PUM is an owner ******DRAWN***** menu, meaning it has the same process as basic AHK menu, the same as from the link I suggested before to be exact: the system enters a model loop:
MSDN wrote: during a modal loop, the system retrieves and dispatches messages without allowing an application the chance to filter the messages in its main message loop
there are some work around, but not straight forward ones.
for your needs, it doesn't matter, if it's PUM or not, since I think the system doesn't handle the mouse wheel on context menus, or otherwise the AHK menu would have it, you may need to do more research
one more thing, or two
- you can use a second script, or another thread to control the mouse scroll and send clicks to the top or bottom of the menu, this is simpler and straight forward I think, just get the height of the context menu, and send the clicks, there might be some calculations involved, but not hard
- even though not as practical, but the menu has a style:
MSDN wrote:MNS_MODELESS: Menu is modeless; that is, there is no menu modal message loop while the menu is active.
I haven't tested it, but it might work.
look here: http://stackoverflow.com/questions/1187 ... -operation
- see things about hooks in here: https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
arcticir
Posts: 647
Joined: 17 Nov 2013, 11:32

Re: How to use the wheel to scroll the menu

26 Jul 2015, 04:50

I say that, regardless of AHK menu or menu PUM
Are capable of rolling
just not use the wheel
click on this button:
Image
Although it is relatively slow.

So I tried to find its source.
Click the button to trigger anything, let menu scrolling.
I guess this should be WINAPI.
And mouse hook should not matter.
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: How to use the wheel to scroll the menu

29 Jul 2015, 00:56

the next scripts must be run separately
CAREFUL: THIS WOULD PRESS THE LAST OR FIRST ITEM IN THE CONTEXT MENU IF THERE WERE NO UP/DOWN ARROW

Code: Select all

WheelDown::
WheelUp::
hWnd := WinExist("ahk_class #32768") ; menu class
WinGetPos, x, y, w, h
(A_ThisHotkey="WheelDown") ? Wheel2Click(x+20, y+h-20, hWnd) :  Wheel2Click(x+20, y+5, hWnd) ; the 20s and 5 are from testing only no calculations
return

Wheel2Click(x, y, hWnd) { ; posting clicks without moving the mouse
; WM_LBUTTONDOWN: https://msdn.microsoft.com/en-us/library/windows/desktop/ms645607(v=vs.85).aspx 
	lParam := x + (y << 16)
	PostMessage, 0x0201, 0x0001, lParam, , ahk_id %hWnd% ; WM_LBUTTONDOWN:=0x0201, MK_LBUTTON:=0x0001
	PostMessage, 0x0202 , 0, lParam, , ahk_id %hWnd% ; WM_LBUTTONUP:=0x0202
}
test it on this and only this script until you know exactly how it works, this is just a simple draft that clicks the top or bottom of the menu

Code: Select all

Space::
Loop, 26
	menu, Long_Long_Menu, add, % chr(64+A_Index) "_First", MenuHandler
Loop, 26
	menu, Long_Long_Menu, add, % chr(64+A_Index) "_Next", MenuHandler
menu, Long_Long_Menu, show
return

MenuHandler:
MsgBox, % A_ThisMenuItem
return
esc::
ExitApp
I'll leave knowing if the menu has an up/down arrow to scroll in the first place, and no DPI awareness!
arcticir
Posts: 647
Joined: 17 Nov 2013, 11:32

Re: How to use the wheel to scroll the menu

30 Jul 2015, 05:21

Very grateful, that solved my problem.

But also the emergence of new problems, the wheel seems to trigger a menu command.
For example the menu:

Code: Select all

Space::
Loop, 2
	menu, Long_Long_Menu, add, % chr(64+A_Index) "_First", MenuHandler
Loop, 2
	menu, Long_Long_Menu, add, % chr(64+A_Index) "_Next", MenuHandler
menu, Long_Long_Menu, show
return
 
MenuHandler:
MsgBox, % A_ThisMenuItem
return
esc::
ExitApp
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: How to use the wheel to scroll the menu

30 Jul 2015, 06:40

MJs wrote: CAREFUL: THIS WOULD PRESS THE LAST OR FIRST ITEM IN THE CONTEXT MENU IF THERE WERE NO UP/DOWN ARROW
I'll leave knowing if the menu has an up/down arrow to scroll in the first place, and no DPI awareness!
arcticir
Posts: 647
Joined: 17 Nov 2013, 11:32

Re: How to use the wheel to scroll the menu

30 Jul 2015, 09:25

Sorry, my English is very bad, I did not immediately understand what you said.
So, how to know if the menu has an up/down arrow?
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: How to use the wheel to scroll the menu

31 Jul 2015, 22:14

arcticir wrote:Sorry, my English is very bad, I did not immediately understand what you said.
So, how to know if the menu has an up/down arrow?
ok, then:

Code: Select all

#if INFO:=IsLongLongMenu()
WheelDown::
WheelUp::
(A_ThisHotkey="WheelDown") ? Wheel2Click(INFO.x+20, INFO.y+INFO.h-20, INFO.hWnd) :  Wheel2Click(INFO.x+20, INFO.y+5, INFO.hWnd)
return
#if

Wheel2Click(x, y, hWnd) { ; Left or right buttons
	lParam := x + (y << 16)
	PostMessage, 0x0201, 0x0001, lParam, , ahk_id %hWnd% ; WM_LBUTTONDOWN:=0x0201, MK_LBUTTON:=0x0001
	PostMessage, 0x0202 , 0, lParam, , ahk_id %hWnd% ; WM_LBUTTONUP:=0x0202
}


IsLongLongMenu(){ ; this is testing and calculating based on basic understading
	hWnd := WinExist("ahk_class #32768")
	SendMessage, 0x01E1 ; MN_GETHMENU:=0x01E1 : Retrieves the menu handle for the current window
	hMenu := errorlevel
	VarSetCapacity(rect, 16, 0)
	DllCall("GetMenuItemRect", uInt, 0, uInt, hMenu, uInt, 0, uInt, &rect) ; get the rect of the top menu item
	WinGetPos, x, y, w, h ; get the popup menu rect
	return, ((NumGet(rect, 4)-y)>10) ? {hWnd:hWnd, x:x, y:y,h:h} : 0 ; the up/down arrow on a 96 DPI setting is 20, so that would be the minumum I'd think

}
CAREFUL: TEST AND SEARCH
arcticir
Posts: 647
Joined: 17 Nov 2013, 11:32

Re: How to use the wheel to scroll the menu

01 Aug 2015, 00:39

Thanks for your help, I think this issue has been the perfect solution. :D
jasonwong
Posts: 1
Joined: 15 Nov 2020, 05:42

Re: How to use the wheel to scroll the menu

15 Nov 2020, 05:45

GREAT JOB
MJs wrote:
31 Jul 2015, 22:14
arcticir wrote:Sorry, my English is very bad, I did not immediately understand what you said.
So, how to know if the menu has an up/down arrow?
ok, then:

Code: Select all

#if INFO:=IsLongLongMenu()
WheelDown::
WheelUp::
(A_ThisHotkey="WheelDown") ? Wheel2Click(INFO.x+20, INFO.y+INFO.h-20, INFO.hWnd) :  Wheel2Click(INFO.x+20, INFO.y+5, INFO.hWnd)
return
#if

Wheel2Click(x, y, hWnd) { ; Left or right buttons
	lParam := x + (y << 16)
	PostMessage, 0x0201, 0x0001, lParam, , ahk_id %hWnd% ; WM_LBUTTONDOWN:=0x0201, MK_LBUTTON:=0x0001
	PostMessage, 0x0202 , 0, lParam, , ahk_id %hWnd% ; WM_LBUTTONUP:=0x0202
}


IsLongLongMenu(){ ; this is testing and calculating based on basic understading
	hWnd := WinExist("ahk_class #32768")
	SendMessage, 0x01E1 ; MN_GETHMENU:=0x01E1 : Retrieves the menu handle for the current window
	hMenu := errorlevel
	VarSetCapacity(rect, 16, 0)
	DllCall("GetMenuItemRect", uInt, 0, uInt, hMenu, uInt, 0, uInt, &rect) ; get the rect of the top menu item
	WinGetPos, x, y, w, h ; get the popup menu rect
	return, ((NumGet(rect, 4)-y)>10) ? {hWnd:hWnd, x:x, y:y,h:h} : 0 ; the up/down arrow on a 96 DPI setting is 20, so that would be the minumum I'd think

}
CAREFUL: TEST AND SEARCH

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Chunjee, Google [Bot], jmone, keylo, mikeyww, PuzzledGreatly, Xtra and 42 guests