01-15-2025, 06:47 PM
JR,
Really nice program and I can reproduce your issue.
So first I replaced your return check code with my subroutine and still see the issue.
So then I noticed that the second time Test is called from inside OnButtonClick - this is a non-UI event thread, and Test does struff that should be on the main UI thread, so I updated your code for this and still see the issue!
Next I realised that the TextBox has focus and the Space key is being sent there and the GraphicsWindow.LastKey remains as "Return" since the Space key event didn't get passed to the GraphicsWindow, it just went to the TextBox. Then I removed the TextBox focus and it worked, but you do need to click inside the textbox to enter a number to it. It is interesting that GW.LastKey does get the key click in the TextBox (this event bubbles up), but GW does not get the Space key. Often once an event is handled it then does not progress up the visual tree to a parent element, so the TextBox says I've used the Space key and no need for any other window elements to get this event.
This the code: WMXJ902.000
And here is version where the TextBox focus is set after the Space has been sent to the GW, this also works: WMXJ902.000-0
Fun little puzzle!
Really nice program and I can reproduce your issue.
So first I replaced your return check code with my subroutine and still see the issue.
So then I noticed that the second time Test is called from inside OnButtonClick - this is a non-UI event thread, and Test does struff that should be on the main UI thread, so I updated your code for this and still see the issue!
Next I realised that the TextBox has focus and the Space key is being sent there and the GraphicsWindow.LastKey remains as "Return" since the Space key event didn't get passed to the GraphicsWindow, it just went to the TextBox. Then I removed the TextBox focus and it worked, but you do need to click inside the textbox to enter a number to it. It is interesting that GW.LastKey does get the key click in the TextBox (this event bubbles up), but GW does not get the Space key. Often once an event is handled it then does not progress up the visual tree to a parent element, so the TextBox says I've used the Space key and no need for any other window elements to get this event.
This the code: WMXJ902.000
And here is version where the TextBox focus is set after the Space has been sent to the GW, this also works: WMXJ902.000-0
Fun little puzzle!