SC: How to get item under mouse?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
autocart
Posts: 839
Joined: 26 Sep 2013 15:22

SC: How to get item under mouse?

Post by autocart »

Hi all,
Is there a way in XY-scripting how to get the item (in list) currently under the mouse cursor (without sending a click e.g. through ahk or similar)?

highend
Posts: 9528
Joined: 06 Feb 2011 00:33

Re: SC: How to get item under mouse?

Post by highend »

XY doesn't expose the content of any pane so to get what you want you could only try to compute it...

AHK
- Get the current mouse coordinates & size of XY's window
- Send a script to XY that reports back the current active pane, all of it's files and folders, the current font and font size for "Main contents", the current line spacing value, status bar visible / not, breadcrumb bar visible / not, menu visible / not, button bar visible / not, visual filter...
- Build internal values of fonts + sizes and their height in pixels. Add line spacing
- Read the visible element (ThunderRT6PictureBoxDC56 / 67)

- Multiply each entry with the height (former step), use the mouse coordinates to see which element would be under it (depending on active pane)...

Ofc you get in trouble if somebody uses the windows font scaling or if the second pane is at the bottom (instead of right to it), horizontal scroll bar visible / not, etc....

Imho not worth the trouble
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

autocart
Posts: 839
Joined: 26 Sep 2013 15:22

Re: SC: How to get item under mouse?

Post by autocart »

thx for the brainstorm, highend,
besides the problems you mentioned I also think it would be a problem if the user simply scrolled down a list (if the content is longer than the display), which happens most of the time.
at least I now am confirmed that I did not overlook anything, thx.

TheQwerty
Posts: 4353
Joined: 03 Aug 2007 22:30

Re: SC: How to get item under mouse?

Post by TheQwerty »

It can be done!

I use a compiled AutoHotkey script to get the mouse coordinates and focus the underlying control if it is over XY - this eliminates the headache caused by the controls changing classNN.
It sends the data back to XY using binoccular222's messenger example.
The XY script then uses the undocumented cell (+ update) SC and takes the painstaking effort of enumerating all items in the list checking to see if the mouse falls within their bounds.


Rather than repeat myself, it's all on GitHub.

Latest Release

klownboy
Posts: 3057
Joined: 28 Feb 2012 19:27

Re: SC: How to get item under mouse?

Post by klownboy »

Autocart and TheQwerty, excellent idea and implementation. It works great and quite snappy considering what's going on in the background. Now, to think of ways to use it. Another case where AHK and XY play so nicely together. Too bad Don couldn't incorporate the AHK.dll library and have it all in one basket. Of course Norton Anti-virus picked the exec file up as "reputation.1" virus and of course it's false positive, but I figured I let you know. Thanks. :appl:

Edit: I wanted to add that it works fine also if the mouse is over a thumbnail (i.e., the thumbnail itself). It doesn't have to be over the filename below the thumb. That may bring some nice possibilities.
Last edited by klownboy on 23 Oct 2014 13:33, edited 2 times in total.

TheQwerty
Posts: 4353
Joined: 03 Aug 2007 22:30

Re: SC: How to get item under mouse?

Post by TheQwerty »

klownboy wrote:Of course Norton Anti-virus picked the exec file up as "reputation.1" virus and of course it's false positive, but I figured I let you know.
:oops: *sigh* It's been quite a while since I've dealt with compiling AHKs. Any suggestions on the "best" way to compile them to avoid false-positive headaches?
Is just disabling compression/UPX enough?

highend
Posts: 9528
Joined: 06 Feb 2011 00:33

Re: SC: How to get item under mouse?

Post by highend »

Great :)

I'll probably port that to PureBasic (when I have enough^^ time). Would drop down the filesize to between 25-50 kb and speed up the loading time... I already have a working Send_WM_COPYDATA snippet so it shouldn't require much work.
*sigh* It's been quite a while since I've dealt with compiling AHKs
Yes, just disable UPX / mpress compression
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

klownboy
Posts: 3057
Joined: 28 Feb 2012 19:27

Re: SC: How to get item under mouse?

Post by klownboy »

I was going to say the same thing. I've used upx http://upx.sourceforge.net/ without any issues before in lieu of the autohotkey/mpress compiler.
By the way, it was only an issue when I extracted it from the zip. No issues after, when I "ran" it with Norton back on line. Of course that may be because I have Norton ignore my XYplorer folders. :whistle:

TheQwerty
Posts: 4353
Joined: 03 Aug 2007 22:30

Re: SC: How to get item under mouse?

Post by TheQwerty »

highend wrote:
*sigh* It's been quite a while since I've dealt with compiling AHKs
Yes, just disable UPX / mpress compression
Which doesn't seem to be enabled anyhow, so I'm not sure what's going on there.

Over half of that size is due to including the icon and I had Compile_AHK including it for everything which is probably overkill. Using ahk2exe instead I get it to 958 KB or 483.50 KB with mpress.

I was going to write the helper in C but decided it wasn't worth the extra effort.

I welcome improvements! ;)

autocart
Posts: 839
Joined: 26 Sep 2013 15:22

Re: SC: How to get item under mouse?

Post by autocart »

Thx very much, The Qwerty,
unfortunately I am too dumb to make it work.
I put
::load "ItemUnderMouse.xys"
(and also tried other formats too) into the address bar, moved the mouse over an item in the list, pressed enter with focus still on AB but nothing happened.
ItemUnderMouse.exe was also in script folder (as was ItemUnderMouse.xys)

I tested it on vista32bit and compiled the exe myself.

What did I do wrong?

highend
Posts: 9528
Joined: 06 Feb 2011 00:33

Re: SC: How to get item under mouse?

Post by highend »

And it doesn't spit out any message at all?

I've just did what you did and it worked fine.
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

klownboy
Posts: 3057
Joined: 28 Feb 2012 19:27

Re: SC: How to get item under mouse?

Post by klownboy »

The best way I found to use / test the script is to assign a user defined command. User | User Defined Commands | Load script file. From there just put in the script name with full path and then Assign Keyboard Shortcut. I used Control Enter to test. Worked great even on a thumbnail well away from the filename. Setting it up this way you don't have to worry about mouse placement...just put the mouse where you want it and hit the key assigned.

autocart
Posts: 839
Joined: 26 Sep 2013 15:22

Re: SC: How to get item under mouse?

Post by autocart »

alright, I tried the "normal" download from github now. this one works as expected.

the "source code" download does not work. in the status bar it says "Invalid script:" if I try to load it.
I also found the reason: The xys-script that works ok has CR+LF as line seperator (DOS-style). The one that does not work has only LF (UNIX-style).

Thank you, The Qwerty, another gem for scripting purposes!!!!!

This one should immediately be added to the scripts-overview!!! Please.

TheQwerty
Posts: 4353
Joined: 03 Aug 2007 22:30

Re: SC: How to get item under mouse?

Post by TheQwerty »

autocart wrote:I also found the reason: The xys-script that works ok has CR+LF as line seperator (DOS-style). The one that does not work has only LF (UNIX-style).
Doh... indeed XY doesn't like that. That's my fault, I have autocrlf enabled in Git so it converts them to LF for storing in the repo, which means the source-archive automatically included by GitHub is wrong, while I built the other archive locally (and thus with CRLF) and uploaded it for the release. :oops:

*sigh* What a mess releasing this has been! :roll:

autocart
Posts: 839
Joined: 26 Sep 2013 15:22

Re: SC: How to get item under mouse?

Post by autocart »

could this be done also for the tree view?
right now it only returns: "The mouse is not over a list pane."

Post Reply