Mouse Event and color

I have designed a piano keyboard using Bevelbuttons and Canvas to color the keys
In order to show the black keys I am using this code for Paint event:

Dim fillColor As Color
If mFilled Then
fillColor = &caaaaaa // Gray
fillColor = &c000000 // Black
End If
g.ForeColor = fillColor
g.FillRect(0, 0, Me.Width, Me.Height)

This code for Mousedown event:

mFilled = Not mFilled

I would like to simulate that a key was pressed by changing its color to gray and come back to black when not used.
What I get now is toggling between black and gray.

Thanks for any help

Return True in MouseDown, then switch your Boolean back in MouseUp.

@Anthony Super!
Now I have to apply this to all my 60 keys :wink:
Thank you

Happy to help!
You should create a subclass of Canvas and do all of the work in that, makes things like this a lot easier.

as Anthony said… you should have 60 instances of a custom class to represent your key… not 60 individual “pieces of code”
the program will be much smaller, and much easier to maintain