|
|
|
05-18-2019, 08:42 AM
|
#1
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
JS_WindowMessage_Post() not working for mouse clicks
Hey all,
I've been trying to send a mouse click via a script.
I'm focusing the Reaper main window. But this somehow doesn't work.
The mouse click isn't executed (can't see any effect), but JS_WindowMessage_Post returns true.
Code:
hwnd = reaper.JS_Window_GetForeground()
x, y = reaper.GetMousePosition()
reaper.JS_WindowMessage_Post(hwnd, "WM_LBUTTONDOWN", 1, 0, x, y)
reaper.JS_WindowMessage_Post (hwnd, "WM_LBUTTONUP", 0, 0, x, y)
|
|
|
05-18-2019, 10:18 AM
|
#2
|
Human being with feelings
Join Date: Jul 2009
Posts: 3,714
|
Two issues:
1) Posting a window message places a message in the message queue of the window and returns without waiting for the thread to process the message. A true return value simply means that the message was successfully posted -- not that the window will obey the message.
2) The x and y coordinates should be client coordinates, not screen coordinates, so you should use ScreenToClient before posting.
|
|
|
05-18-2019, 07:20 PM
|
#3
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
It's still not working and I have no idea why...
This is my current code. I somehow have the feeling that I'm missing some important piece of the puzzle:
Code:
hwnd = reaper.JS_Window_GetForeground()
x1, y1 = reaper.GetMousePosition()
x, y = reaper.JS_Window_ClientToScreen(fore, x1, y1 )
reaper.JS_WindowMessage_Post(hwnd, "WM_LBUTTONDOWN", 1, 0, x, y)
reaper.JS_WindowMessage_Post(hwnd, "WM_LBUTTONUP", 0, 0, x, y)
|
|
|
05-19-2019, 04:27 AM
|
#4
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
Quote:
Originally Posted by _Stevie_
It's still not working and I have no idea why...
This is my current code. I somehow have the feeling that I'm missing some important piece of the puzzle:
Code:
hwnd = reaper.JS_Window_GetForeground()
x1, y1 = reaper.GetMousePosition()
x, y = reaper.JS_Window_ClientToScreen(fore, x1, y1 )
reaper.JS_WindowMessage_Post(hwnd, "WM_LBUTTONDOWN", 1, 0, x, y)
reaper.JS_WindowMessage_Post(hwnd, "WM_LBUTTONUP", 0, 0, x, y)
|
Not sure if that's it (didn't test) but
Code:
x, y = reaper.JS_Window_ClientToScreen(fore, x1, y1 )
should be, no?
Code:
x, y = reaper.JS_Window_ClientToScreen(hwnd, x1, y1 )
|
|
|
05-19-2019, 04:30 AM
|
#5
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
Yeah sorry, it's correct in my script. I changed it only for pasting it in the forums
So, that's not the issue
Does the script work for you, when you execute it in Reaper?
|
|
|
05-19-2019, 04:58 AM
|
#6
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
Quote:
Originally Posted by _Stevie_
Does the script work for you, when you execute it in Reaper?
|
I tried it meanwhile (with fore replaced by hwnd) and no, doesn't do here anything either.
No idea what's wrong though, sorry.
|
|
|
05-19-2019, 06:03 AM
|
#7
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
Thanks nofish, at least I know it's not specific to my system
Edgemeal has it working in some of his scripts. I think I have to check those out...
|
|
|
05-20-2019, 12:28 AM
|
#8
|
Human being with feelings
Join Date: Apr 2014
Posts: 4,171
|
Quote:
Originally Posted by _Stevie_
Thanks nofish, at least I know it's not specific to my system
Edgemeal has it working in some of his scripts. I think I have to check those out...
|
Hey Stevie,
According to Julian's post above - you need ScreenToClient not ClientToScreen.
|
|
|
05-20-2019, 04:52 AM
|
#9
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
Ohh whoops! Looked up the wrong function in the API... :O
Thanks dude, fingers crossed this will work now. Checking in a few!
|
|
|
05-20-2019, 07:36 AM
|
#10
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
*sigh*, still not working:
Code:
hwnd = reaper.JS_Window_GetForeground()
title = reaper.JS_Window_GetTitle( hwnd )
x1, y1 = reaper.GetMousePosition()
x, y = gfx.screentoclient(x1, y1)
reaper.ShowConsoleMsg(x1 .." " .. y1 .. "\n")
reaper.ShowConsoleMsg(x .." " .. y .. "\n")
reaper.JS_WindowMessage_Post(hwnd, "WM_LBUTTONDOWN", 1, 0, x, y)
reaper.JS_WindowMessage_Post(hwnd, "WM_LBUTTONUP", 0, 0, x, y)
The values of x, x1 and y, y1 are the same btw. With the difference, that screentoclient adds a .0 at the end.
My suspicion is: the click is not executed at all.
|
|
|
05-20-2019, 07:52 AM
|
#11
|
Human being with feelings
Join Date: Jul 2009
Posts: 3,714
|
reaper.JS_Window_ScreenToClient(hwnd, x1, y1)
|
|
|
05-20-2019, 08:47 AM
|
#12
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
Still no click, nowhere
|
|
|
05-20-2019, 09:26 AM
|
#13
|
Human being with feelings
Join Date: Jul 2009
Posts: 3,714
|
I quickly checked it on a few windows, including the MIDI editor and IDE, and everything seems to work fine.
Perhaps the problem lies in GetForeground. AFAIK the foreground window is usually the top-level framed window, while the mouse clicks should be sent to the target child window.
Could you let us know which windows you are working with?
|
|
|
05-20-2019, 12:41 PM
|
#14
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
Oh geez, you could be right. In that case, the Reaper main window had focus.
I will check and let you know. Thanks for digging into it!
|
|
|
05-20-2019, 12:51 PM
|
#15
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
Unfortunately, that didn't work, either.
May I ask: when I execute the script, then a left click should happen e.g.
the edit cursor should move, when I hover with the mouse over the MIDI editor
or arrange window, is that correct?
|
|
|
05-20-2019, 02:59 PM
|
#16
|
Human being with feelings
Join Date: Jul 2009
Posts: 3,714
|
Quote:
when I hover with the mouse over the MIDI editor
or arrange window, is that correct?
|
If you are just hovering over a window, try:
Code:
x, y = reaper.GetMousePosition()
w = reaper.JS_Window_FromPoint(x, y)
x, y = reaper.JS_Window_ScreenToClient(w, x, y)
reaper.JS_WindowMessage_Post(w, "WM_LBUTTONDOWN", 1, 0, x, y)
reaper.JS_WindowMessage_Post(w, "WM_LBUTTONUP", 0, 0, x, y)
If you then use Ctrl+S to run the script in the IDE, while hovering over the arrange view or piano roll, this should send a Ctrl+mouseclick to that window.
EDIT: Corrected silly error in function name.
Last edited by juliansader; 05-22-2019 at 02:06 PM.
|
|
|
05-20-2019, 04:41 PM
|
#17
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
Hah! That worked, thanks Julian!
Instead of
Code:
x, y = reaper.JS_Window_ClientFromScreen(w, x, y)
it was:
Code:
x, y = reaper.JS_Window_ScreenToClient(w, x, y)
Just documenting this here, if someone else reads this
|
|
|
05-20-2019, 07:46 PM
|
#18
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
Thanks, didn't know the JS plugin can simulate the clicking of mouse before.
If I change WM_LBUTTONDOWN to WM_RBUTTONDOWN, it will simulate a right click. What else parameters can replace it and simulate more action from mouse and keyboard?
|
|
|
05-21-2019, 05:14 AM
|
#20
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
Quote:
Originally Posted by _Stevie_
|
Thanks.
|
|
|
05-22-2019, 12:17 AM
|
#21
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
I tried this to simulate a left drag
Code:
x, y = reaper.GetMousePosition()
w = reaper.JS_Window_FromPoint(x, y)
xc, yc = reaper.JS_Window_ScreenToClient(w, x, y)
reaper.JS_WindowMessage_Post(w, "WM_LBUTTONDOWN", 1, 0, xc, yc)
reaper.JS_Mouse_SetPosition(x-200, y)
x, y = reaper.GetMousePosition()
xc, yc = reaper.JS_Window_ScreenToClient(w, x, y)
reaper.JS_WindowMessage_Post(w, "WM_LBUTTONUP", 0, 0, xc, yc)
But it didn't make a left drag, but a alt+left drag?
|
|
|
05-22-2019, 08:24 AM
|
#22
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
|
Quote:
Originally Posted by dsyrock
I tried this to simulate a left drag
But it didn't make a left drag, but a alt+left drag?
|
This test worked for me, it moved an item in arrange view to the right 100 pixels.
Code:
x = 568
y = 240
w = reaper.JS_Window_FromPoint(x, y)
xc, yc = reaper.JS_Window_ScreenToClient(w, x, y)
reaper.JS_WindowMessage_Send(w, "WM_LBUTTONDOWN", 1, 0, xc, yc)
for n = xc, xc + 100 do
reaper.JS_WindowMessage_Send(w, "WM_MOUSEMOVE", 1, 0, n, yc)
end
reaper.JS_WindowMessage_Send(w, "WM_LBUTTONUP", 0, 0, xc, yc)
edit, This works same to move also,
Code:
for n = 1, 100 do
reaper.JS_WindowMessage_Send(w, "WM_MOUSEMOVE", 1, 0, n, yc)
end
Last edited by Edgemeal; 05-22-2019 at 02:01 PM.
|
|
|
05-22-2019, 08:32 AM
|
#23
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,750
|
FWIW I'd recommend using Send rather than Post for this purpose. PostMessage is really only needed when sending windows messages from threads other than the main (UI) thread, which is more or less never in this context. Maybe you'd use PostMessage for just tossing a single message to some non-REAPER window and not caring about what happens as a result, but for anything else, SendMessage.
|
|
|
05-22-2019, 08:53 AM
|
#24
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
|
Thanks for that info, schwa!
|
|
|
05-22-2019, 12:32 PM
|
#25
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
Thanks Edgemeal and schwa. And I figure it out what make my script turn to alt+drag instead of drag. I assign the test script to "Alt+1",so the alt key mess up the script.
And is it possible to make this work in two different windows? For example, drag a file from Media Explorer to main window
This doesn't work
Code:
x, y = reaper.GetMousePosition()
w = reaper.JS_Window_FromPoint(x, y)
xc, yc = reaper.JS_Window_ScreenToClient(w, x, y)
reaper.JS_WindowMessage_Send(w, "WM_LBUTTONDOWN", 1, 0, xc, yc)
reaper.JS_Mouse_SetPosition(x-400, y)
x, y = reaper.GetMousePosition()
wnew = reaper.JS_Window_FromPoint(x, y)
xc, yc = reaper.JS_Window_ScreenToClient(wnew, x, y)
reaper.JS_WindowMessage_Send(wnew, "WM_LBUTTONUP", 0, 0, xc, yc)
And one more question, what does wParamLow and wParamHigh mean?
Last edited by dsyrock; 05-22-2019 at 08:23 PM.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 06:47 AM.
|