KeyDown and MouseEnter won't get along

Trying to update an old desktop app from 2000 to run on 64bit. All outdated graphics things. Seemed easy to fix and was up to a point. The app uses many mouseEnters and keyDowns to change the color of text in a canvas and play a tone. The updated code in the canvas paint each work separately but not together. Only the keyDown will work mouseEnter stops working. I use the canvas.mouseEnter and the window.keyDown to trigger the canvas paint code. Con’t find the conflict, help. I was never very good at this and haven’t used Xojo since 2015. I think I forgot more than I used to know! The canvas.paint code is below. Thanks.

//normal state - black to red on mouseenter/exit
if isEnter = true then
  g.ClearRectangle(0, 0, me.Width, me.Height)
  g.TextFont="Charcoal"
  g.TextSize=18
  g.DrawingColor=RGB(300,0,0)//red
  g.DrawString "do",5,20
elseif isEnter = false Then
  g.ClearRectangle(0, 0, me.Width, me.Height)
  g.TextFont="Charcoal"
  g.TextSize=18
  g.DrawingColor=RGB(0,0,0)//black
  g.DrawString "do",5,20
End if

//color state - black to blue on mouseenter/exit
if  ColorBox.value  and isEnter = true Then
  g.ClearRectangle(0, 0, me.Width, me.Height)
  g.TextFont="Charcoal"
  g.TextSize=18
  g.DrawingColor=RGB(10,10,255)//blue
  g.DrawString "do",5,20
elseif ColorBox.value = false and isEnter = false Then
  g.ClearRectangle(0, 0, me.Width, me.Height)
  g.TextFont="Charcoal"
  g.TextSize=18
  g.DrawingColor=RGB(0,0,0)//black
  g.DrawString "do",5,20
end if

//keyDown normal state black to red
if isDown = true then
  g.ClearRectangle(0, 0, me.Width, me.Height)
  g.TextFont="Charcoal"
  g.TextSize=18
  g.DrawingColor=RGB(300,0,0)//red
  g.DrawString "do",5,20
elseif isDown = false then
  g.ClearRectangle(0, 0, me.Width, me.Height)
  g.TextFont="Charcoal"
  g.TextSize=18
  g.DrawingColor=RGB(0,0,0)//black
  g.DrawString "do",5,20
end

//keyDown color state black to blue
if  ColorBox.value and isDown = true Then
  g.ClearRectangle(0, 0, me.Width, me.Height)
  g.TextFont="Charcoal"
  g.TextSize=18
  g.DrawingColor=RGB(10,10,255)//blue
  g.DrawString "do",5,20
ElseIf ColorBox.value and isDown = False then
  g.ClearRectangle(0, 0, me.Width, me.Height)
  g.TextFont="Charcoal"
  g.TextSize=18
  g.DrawingColor=RGB(0,0,0)//black
  g.DrawString "do",5,20
end

What is the code in MouseEnter and KeyDown? When do you clear your boolean values?

Thanks Tim. Right, I did forget to add that. For mouseEnter I have:
me.Invalidate()

isEnter = True
isExit = False

And for the kewDown I have:
Canvas1.Invalidate()

If keyboard.ShiftKey=false and (key="d") then
  isDown = True
  
Else
  isDown = False

end

Thanks again.

Thanks for your offer of help Tim. I figured it out finally.

1 Like

For the benefit of future seekers, maybe you could share the solution?

Judging from the lack interest in my topic I don’t think anyone would really care. All I can say is that I finally realized that I need less boolean and more brains on my part to solve it. :crazy_face:

not everyone is in front of the forum 27/7 to answer inmediatly. Also, looks like there is less and less users each day.

Anyway, if you return TRUE in the KeyDown event, as the docs says “it means that no further processing is to be done with the Key”, so you have to return false to have a KeyUp Event.

1 Like

Thanks Ivan. I tried that but I already had such a boolean mess started that it didn’t work. After Tim’s post I went back and simplified things to sort it out. Anyway, I didn’t mean anything derogatory against the Xojo forum in my comments, everyone has always been very helpful. There are a lot more important issues that need their skills I’m sure. Thanks

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.