|
|
|
03-31-2023, 06:00 AM
|
#1
|
Human being with feelings
Join Date: Mar 2022
Posts: 62
|
[Lua] [Reascript] How to check if mouse button is down/released
"Hello, i'm writing a reascript that i want to bind to my
Control+LeftMouseClick. The script will do different things depending
on the context.
One function will be the default action - toggle item selection. However,
the script seems to get triggered twice, once when i press the left mouse
button and once when i release it. This toggles the item selection twice
leaving me where i started...doh
How can i solve this problem? How can i make sure the script only runs
when the left mouse is clicked, not released? Thank you"
|
|
|
03-31-2023, 06:24 AM
|
#2
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,622
|
JS-extension has a function called for getting the mouse-keyboard-modifiers. I think it is JS_Mouse_GetState.
You can find the JS-extension-thread pinned in this subforum...
|
|
|
03-31-2023, 07:19 AM
|
#3
|
Human being with feelings
Join Date: Mar 2022
Posts: 62
|
reaper.JS_Mouse_GetState() doesn't seem to be able to distinguish between
down/release of a mouse button, only which mouse button has been pressed.
Turns out, after doing some more debugging, that i diagnosed the problem
wrong. The problem is that when i click on an item, it selects it. So
that when the reascript gets called, the item is always selected. The
problem is that the script gets called after the initial click
action. Therefore the original state is destroyed and i cannot toggle
it. Not sure you can get around that.
|
|
|
03-31-2023, 08:08 AM
|
#4
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,622
|
If I got it right, you can do the same by not using mouseclicks.
The script does the following:
You use GetItemFromPoint. If the item found is selected, deselect it, if it's deselected, select it(so your toggle behavior).
Then associates it to a shortcut.
Now you just hover over the item that you want to toggle and use the shortcut instead of clicking.
It's not perfect but a workaround...
|
|
|
03-31-2023, 08:17 AM
|
#5
|
Human being with feelings
Join Date: Mar 2022
Posts: 62
|
You got me right. However the whole point of the script is to make a 'meta-ctrl+leftclick' function that does different things depending on the context. In certain contexts i want to preserve the default behavior, which is to, in the ctrl+leftclick case, toggle the item selection. However that doesn't seem to be possible as the script gets called after the item has been clicked, which selects it, thereby destroying the original state and making toggling impossible.
|
|
|
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 07:21 AM.
|