Lua Script Help: Any way to get Right mouse-click event instead of just Left?

Pretty much title. I’m currently reworking aquova’s color scripts to make them a little more usable for my workflow. Domjohn’s Color Shading uses dlg:shades and is able to click on those colors to immediately select/add one as your Foreground color.

So I borrowed that functionality a bit and it works, but I want to be able to left click a color to add to FG and right click a different color to add to BG.

> -- Generates the color gradients and displays them
> function showOutput(color1, color2)
>     local dlg
> 	dlg = Dialog
> 	{
> 		title="Found Hues"
> 	}
>     -- Find the slopes of each component of both colors
>     local m = {
>         r=( -,
>         g=( -,
>         b=( -,
>         a=(color1.alpha - color2.alpha)
>     }
>     for i=0,numHues do
>         -- Linearly find the colors between the two initial colors
>         local newRed = - math.floor(m.r * i / numHues)
>         local newGreen = - math.floor(m.g * i / numHues)
>         local newBlue = - math.floor(m.b * i / numHues)
>         local newAlpha = color1.alpha - math.floor(m.a * i / numHues)
>         local newC = Color{r = newRed, g = newGreen, b = newBlue, a = newAlpha}
>         -- Put every entry on a new row
> 		--dlg:newrow()
>         --dlg:color{ color = newC }
> 		dlg:shades{ id='hue', label='Hue '.. i+1,
>            colors={ newC },
>            onclick=function(ev) app.fgColor=ev.color end }
> 	end
>     dlg:button{ id="ok", text="OK" }
>     dlg:show()
> end


So at the moment I can left click any of these “:shades” colors (Hue 1-5) and it will replace my Foreground color.
How can I either use RMB to right-click and select a Background color, or at the very least what’s the least-painful way of being able to do the “Switch Colors” command while the dialog is open?


So according to this: GitHub - aseprite/api: Scripting API for Aseprite
Mouse buttons are seen as global constants, which is great.

Elsewhere, in, I found an example of these constants in action, as “button=MouseButton.Left | MouseButton.Right,”
So now remains the question… how do I check which “button” is being used with “onclick=function(ev)”? How can I tie these two things together? I can’t for the life of me find any examples or instances or anything because this is all custom and different.

Finally got around to looking into this for my plugin. Here’s the solution! :slight_smile:

onclick = function(ev)
  if(ev.button == 1) then
    app.fgColor = ev.color
  elseif(ev.button == 2) then
    app.bgColor = ev.color


I was about to post a bug report when I found this, much to my relief. I thought I’d resurrect the thread, as it may impact either of you or maybe you have suggestions if you’ve already seen this.

When I try to assign to app.bgColor within the conditional check ev.button == MouseButton.RIGHT, right clicking on the color shade replaces the selected palette index with the color shade if the palette is unlocked (can be edited).

If the foreground color is set to that palette index, the foreground color will change to match. Normally, that could be the correct behavior, but here it’s confusing.

Creating a separate button, accessing the shades’ colors from, then assigning bgColor results in the same.

This can also impact a script’s attempt to get or read the app.bgColor.

I checked that I was in RGB color mode and that my right click wasn’t set to a conflicting function under Preferences > Editor > Right Click. This came up for me in versions 1.3 beta3 and 1.2.27.

Currently, I’m trying this work-around:

app.fgColor = clr

This command may not have been available when the question was first raised. I’ve not tested enough to see if this approach has drawbacks of its own.

Thank you. Best,