Old 09-29-2019, 09:21 AM   #721
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,041
Default

You could compare against previous state and only execute if state has changed compared to previous state, something like this:

Code:
prevState = -1

function main()
  A=reaper.JS_Mouse_GetState(-1)
  reaper.defer(main)
  if prevState ~= A then
   if A == 5 then
      reaper.ShowConsoleMsg("CMD+Click")
    end
  end
  prevState = A
end

main()
Makes use of a global variable though, not sure if there'd be a way around it..
nofish is offline   Reply With Quote
Old 09-29-2019, 09:38 AM   #722
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,724
Default

Thanks nofish, I was thinking of something like that, but my brain is so much out of coding... Need to warm up again
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 09-30-2019, 03:25 PM   #723
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,748
Default

As explained by nofish, in previous versions of the extension, you could detect new key pressed by comparing the current state with the previous state. My own scripts also use such comparisons.

There were two complications that required careful coding:

* If the defer cycles are slow, a key can be pressed and released in-between your script's defer cycles, so VKeys_GetState may overlook some quick key presses.

* If a key is held down, multiple KEYDOWN messages will be sent, so to distinguish new key presses, a comparison of VKeys_GetDown states is required.

The new v0.993 of the extension handles auto-repeated KEYDOWN messages better: All auto-repeated messages are disregarded, and the two complications are therefore hopefully solved.

It is now possible to check for new key presses (since the previous defer cycle) with a single VKeys_GetDown, using cutoffTime = time_precise() of the previous cycle.
juliansader is offline   Reply With Quote
Old 10-01-2019, 01:32 PM   #724
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,724
Default

Thanks Julian, something to digest!


Thanks for all your help guys. My script comes along nicely.
I'm coding a "glue tool" script. I got the intercepting and mouse cursor loading
working fine.

But as you can see in my GIF, after terminating the script, a yellow arrow cursor appears, since I'm setting the default cursor. Only when moving the mouse, the correct pencil cursor appears.

Is there a way to set it to the cursor that was used BEFORE the script was executed?
Or will I need to make a 1 pixel movement back and forth to force update the cursor?



__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 10-01-2019, 01:57 PM   #725
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,748
Default

You can try using JS_Mouse_GetCursur to get the current cursor when your script starts, and then restore that cursor with JS_Mouse_SetCursor when the script exits.
juliansader is offline   Reply With Quote
Old 10-01-2019, 02:00 PM   #726
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,724
Default

How cool! JS_Mouse_GetCursor exists! Didn't know! As usual I scanned Xraym's API website, but couldn't find it there. Checking if that works...

EDIT: Woooop, it worked!!!
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 10-02-2019, 08:14 AM   #727
reapero
Human being with feelings
 
Join Date: Aug 2011
Posts: 203
Default

This script looks awesome Stevie!
reapero is offline   Reply With Quote
Old 10-02-2019, 02:34 PM   #728
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,724
Default

Hah thanks man! Still need to take care of a few corner cases, but otherwise it comes along nicely.
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 10-11-2019, 06:52 AM   #729
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,555
Default

An idea I had for some days now, as I see so many useful examples and snippets, what about adding an example-folder to the repository, so the examples don't get lost in this thread?
That can be filled by all of us, who have examples posted in here.
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old Yesterday, 01:42 AM   #730
reapero
Human being with feelings
 
Join Date: Aug 2011
Posts: 203
Default

Mespotine yes!! That would surely encourage most of us noob coders to try things out and learn from you guys. At the same time, i guess this would make this thread more relevant (deeper sort of posts so to speak), since a lot of the simpler questions could be answered just by digging in the examples.

+1000! Great idea!
reapero is offline   Reply With Quote
Old Yesterday, 06:49 AM   #731
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,041
Default

I also like this suggestion.
'ReaTeam' has something similar I find helpful too:
https://github.com/ReaTeam/ReaScripts-Templates
nofish is offline   Reply With Quote
Old Yesterday, 02:42 PM   #732
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,748
Default

Good idea.

I created a new "js_ReaScriptAPI" folder in the ReaTeam repository that nofish linked to above.
juliansader 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 06:57 PM.


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