Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 03-31-2023, 06:00 AM   #1
captaincurrie
Human being with feelings
 
Join Date: Mar 2022
Posts: 62
Default [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"
captaincurrie is offline   Reply With Quote
Old 03-31-2023, 06:24 AM   #2
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,622
Default

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...
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is online now   Reply With Quote
Old 03-31-2023, 07:19 AM   #3
captaincurrie
Human being with feelings
 
Join Date: Mar 2022
Posts: 62
Default

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.
captaincurrie is offline   Reply With Quote
Old 03-31-2023, 08:08 AM   #4
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,622
Default

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...
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is online now   Reply With Quote
Old 03-31-2023, 08:17 AM   #5
captaincurrie
Human being with feelings
 
Join Date: Mar 2022
Posts: 62
Default

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.
captaincurrie is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:21 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.