|
|
|
06-29-2018, 01:08 PM
|
#1
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
Hold key to run script?
Hello!
I was wondering if it is possible to hold down a key to run a script? So say I am working in reaper and I hold down the A key, it would run a script until I let go of the A key and then terminate the script.
Based on searching, my current solution is really clunky. It requires a graphics window to be open, but my script doesn't need that. It also requires the script be run for around 0.5 seconds at least, which is really annoying.
Here is my example:
Code:
function msg(m)
reaper.ShowConsoleMsg(tostring(m).."\n")
end
-- The A key is the hotkey
local hotkey = 97
local timeWhenPressed, timeHeld, charHotkey
-- This is called when the script starts
function example_init()
msg("key down")
timeWhenPressed = reaper.time_precise()
reaper.defer(example_update)
end
function example_update()
charHotkey = gfx.getchar(hotkey)
timeHeld = reaper.time_precise() - timeWhenPressed
if timeHeld > 0 then
msg("running")
end
-- Hotkey up
if charHotkey == 0 and timeHeld > 0.5 then
msg("key up")
else
reaper.defer(example_update)
end
gfx.update()
reaper.UpdateArrange()
end
gfx.init("test", 0, 0, 0, 0, 0)
example_init()
If you bind this script to the A key, when you hold the key down it runs, and then it will terminate when you let go.
|
|
|
06-29-2018, 02:07 PM
|
#2
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Scripts can't check the keyboard state without a graphics window open, and the keyboard/OS doesn't actually start sending repeated signals for a key for a half second or so after you first click it.
Radial Menu uses roughly the same setup you've worked out - if I get a chance later I'll try to extract the appropriate function to see if there are any notable differences.
Worth noting that some keys and some foreign keyboards won't behave for this application - I ran into a few situations where I had to tell people "sorry, bind it to a different key" because of Reaper/OS limitations.
|
|
|
06-30-2018, 07:13 AM
|
#3
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
Quote:
Originally Posted by Lokasenna
Scripts can't check the keyboard state without a graphics window open, and the keyboard/OS doesn't actually start sending repeated signals for a key for a half second or so after you first click it.
Radial Menu uses roughly the same setup you've worked out - if I get a chance later I'll try to extract the appropriate function to see if there are any notable differences.
Worth noting that some keys and some foreign keyboards won't behave for this application - I ran into a few situations where I had to tell people "sorry, bind it to a different key" because of Reaper/OS limitations.
|
Well shoot, that sucks. I don't really mind the graphics windows popping up because its in the corner and goes away when you let go of the button. It's the half second delay that is a deal breaker. It looks like what I wanted to do isn't really an option I suppose.
Thanks for the help though!
|
|
|
06-30-2018, 07:33 AM
|
#4
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Incidentally, you might want to have a look on ReaPack. I forgot about this one: Repeat Action.
|
|
|
06-30-2018, 08:09 AM
|
#5
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
Quote:
Originally Posted by Lokasenna
Incidentally, you might want to have a look on ReaPack. I forgot about this one: Repeat Action.
|
That looks cool. Having trouble getting it working though. It's saying I have an invalid action ID when I follow the instructions. I'm not sure it would work for my purposes though.
I'm trying to make a Melodyne-ish zoom tool, where you hold a button and mouse movement in the x and y directions influences horizontal and vertical zoom. I would need each call to the script to remember the mouse position it was at in the previous call.
|
|
|
06-30-2018, 10:06 AM
|
#6
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Did you run the "Create a new action" script it installs? (Should show up as an action in your action list)
|
|
|
06-30-2018, 12:39 PM
|
#7
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
Quote:
Originally Posted by Lokasenna
Did you run the "Create a new action" script it installs? (Should show up as an action in your action list)
|
Yeah I did, I get an error message if I try to run the action it creates.
|
|
|
06-30-2018, 12:41 PM
|
#8
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Will have a look, thanks. What action ID did you give it?
|
|
|
06-30-2018, 01:21 PM
|
#9
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
Quote:
Originally Posted by Lokasenna
Will have a look, thanks. What action ID did you give it?
|
I wasn't sure what to do so I just called it "TEST".
|
|
|
06-30-2018, 02:14 PM
|
#10
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
No, the action you told it to run - first box in the dialog.
|
|
|
06-30-2018, 05:14 PM
|
#11
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
Quote:
Originally Posted by Lokasenna
No, the action you told it to run - first box in the dialog.
|
I'm guessing that's where I went wrong. I put that as TEST. Not quite sure how it works so I didn't know what to do.
|
|
|
06-30-2018, 08:00 PM
|
#12
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
You need to give it an action number from the Action List - there's a column listing them, or you can right-click an action and Copy the ID.
Paste that in the script window, give it a name, a time delay, and whether or not it's a MIDI Editor action.
|
|
|
07-02-2018, 10:02 AM
|
#13
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
Quote:
Originally Posted by Lokasenna
You need to give it an action number from the Action List - there's a column listing them, or you can right-click an action and Copy the ID.
Paste that in the script window, give it a name, a time delay, and whether or not it's a MIDI Editor action.
|
Ah ok, I see. Unfortunately I'm not sure it would work for me since the script would need to remember the position of the mouse between repeats.
|
|
|
07-02-2018, 12:29 PM
|
#14
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Scripts can store data in Reaper's .ini files or write directly to a text file themselves, so then the next instance of the script could look for that and read the data back in.
|
|
|
07-02-2018, 02:35 PM
|
#15
|
Human being with feelings
Join Date: Dec 2011
Posts: 506
|
Quote:
Originally Posted by Lokasenna
Scripts can store data in Reaper's .ini files or write directly to a text file themselves, so then the next instance of the script could look for that and read the data back in.
|
Interesting. I'll take a look at that when I get the chance, thanks for the info!
|
|
|
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 03:14 PM.
|