View Single Post
Old 05-26-2023, 03:04 PM   #12
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,689
Default

Here is alternative version with ImGui:



Assign it to some shortcut key, hold down that key and drag away. Once you release it the script will stop

Only downside with this one is that Option "Ignore FX CHAIN keyboard shorcut..." needs to be checked (this is because the key-hold voodoo but we can remove that and make it normal script)

Code:
local r = reaper

START_TIME = reaper.time_precise()
CUR_PREF = reaper.SNM_GetIntConfigVar("alwaysallowkb", 1)

local key_state = reaper.JS_VKeys_GetState(START_TIME - 2)
for i = 1, 255 do
    if key_state:byte(i) ~= 0 then
        reaper.JS_VKeys_Intercept(i, 1);
        KEY = i
    end
end
if not KEY then return end

local function Key_held() return r.JS_VKeys_GetState(START_TIME - 2):byte(KEY) == 1 end

local function Release()
    if not KEY then return end
    r.JS_VKeys_Intercept(KEY, -1)
    r.SNM_SetIntConfigVar("alwaysallowkb", CUR_PREF)
end

local ctx = r.ImGui_CreateContext("GUI DRAW")
local DL =  r.ImGui_GetWindowDrawList( ctx )

local start_x, start_y = r.ImGui_PointConvertNative(ctx, r.GetMousePosition())

function Main()
  if not Key_held() then return end
  
  local x,y = r.ImGui_PointConvertNative(ctx, r.GetMousePosition())
  r.ImGui_SetNextWindowPos( ctx, start_x - 200 , start_y - 200 )    
  r.ImGui_SetNextWindowSize(ctx, 1000, 1000)
  if reaper.ImGui_Begin(ctx, 'ALPHA', false, r.ImGui_WindowFlags_NoBackground() | r.ImGui_WindowFlags_NoDecoration() | r.ImGui_WindowFlags_AlwaysAutoResize() | r.ImGui_WindowFlags_NoMove()) then
     r.ImGui_SetNextWindowPos( ctx, start_x - 500 , start_y )  
     r.ImGui_SetNextWindowSizeConstraints( ctx, 200, 50, 200, 50 )
     
     if reaper.ImGui_Begin(ctx, 'START', false) then
        reaper.ImGui_Text(ctx, "START DRAGING WITH MOUSE")
        r.ImGui_End(ctx)
     end
     
     if r.ImGui_IsMouseDown(ctx, 0) then
        if not SX then
          SX, SY = x, y
        end
        r.ImGui_DrawList_AddRectFilled( DL, SX, SY, x, y, 0x2222AA55 )
     end
     
     if r.ImGui_IsMouseReleased(ctx, 0) then
        r.ShowConsoleMsg(("X : %d , Y : %d, XE : %d, YE : %d"):format(SX, SY, x, y) .. '\n')
     end
     
     r.ImGui_End(ctx)
  end
  
  r.defer(function() xpcall(Main, Release) end)
end
  
r.atexit(Release)
r.defer(Main)
Needs ReaImgui for drawing and JS_API for intercepting shortcut key
Sexan is offline   Reply With Quote