GraphicsWindow.LastKey - Printable Version +- Small Basic Forum (https://litdev.uk/mybb) +-- Forum: Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=1) +--- Forum: Standard Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=2) +--- Thread: GraphicsWindow.LastKey (/showthread.php?tid=210) Pages:
1
2
|
GraphicsWindow.LastKey - jrmrhrb00 - 01-15-2025 This is a little confusing, but here goes! I have a program that I want to rerun for a second or more times. So, I clear the GraphicsWindow, and tell it to rerun by using a button. The problem I am having is: in the first run I use this: While key <> "Return" key = GraphicsWindow.Lastkey EndWhile This is to hold the program until I hit the return key. That works just fine. Then steps in "GraphicsWindow.LastKey" That function is read only. The problem is there is no way to reset it in standard "Small Basic" and it remembers the key was used in the first round of the program. So, on the second round the program zips right through the while loop. To work properly GraphicsWindow.LastKey needs to reset for the second or more rounds of the program. I looked in the LitDev Extension. Didn't see any way to reset it. Any suggestions of how to do it? Maybe, LitDev could add it to the extension? JR RE: GraphicsWindow.LastKey - litdev - 01-15-2025 Depending on what your program actually does this may not be the best approach, but the following may work for you. Others may have different approaches, maybe LDUtilities.KeyDown, GraphicsWindow.KeyDown event - a challenge to find different ways to write WaitForReturnKey subroutine? Code: GraphicsWindow.Show() RE: GraphicsWindow.LastKey - jrmrhrb00 - 01-15-2025 LitDev, In my program I put the following: While key <> "Return" key = GraphicsWindow.Lastkey EndWhile LDTextWindow.SendKey(GraphicsWindow.Title,"Space") 'Send a Space key so initially LastKey is not Return key=GraphicsWindow.LastKey TW.WriteLine(key) GraphicsWindow.LastKey still thinks it was the "Return" key Then I tried just this: While key <> "Return" key = GraphicsWindow.Lastkey EndWhile TextWindow.WriteLine("H") When I run this and hit the return key it doesn;t do the TW. Any idea? RE: GraphicsWindow.LastKey - litdev - 01-15-2025 Hi, interesting. For the first one, GW needs to be present and it seems that processessing of the key takes some time to fire and register async events by the OS, so some delays let it filter through. Code: GraphicsWindow.Show() For second one, it works for me when GW.Show() is used. Code: GW.Show() RE: GraphicsWindow.LastKey - jrmrhrb00 - 01-15-2025 LitDev, This snippet works now. I agree. "Strange" GW.Show() While key <> "Return" key = GraphicsWindow.Lastkey EndWhile TextWindow.WriteLine("H") I am pretty sure in my program that the LDTextWindow.SendKey doesn't reset GraphicsWindow.LastKey. I put a TW.Writeline(GraphicsWindow.LastKey in front of the wait loop and for the second run of the program it shows the "Return" key. It should show the space key, but doesn't. Would it be possible in the extension under utilities to add a reset function to GraphicsWindow.LastKey? JR Here is what I have in the actual program: 'TW.WriteLine(GraphicsWindow.LastKey) While key <> "Return" key = GraphicsWindow.Lastkey EndWhile Program.Delay(10) LDTextWindow.SendKey(GraphicsWindow.Title,"Space") 'Send a Space key so initially LastKey is not Return Program.Delay(10) key=GraphicsWindow.LastKey TW.WriteLine(key) It never shows "Space as the last key. Only "Return" RE: GraphicsWindow.LastKey - litdev - 01-15-2025 Please try the subroutine method which sets key and Lastkey before the loop, you don't appear to be doing this. This works every time for me, so I feel there may be something else going on in your program and would like to understand that first. There are other ways also to just wait for a Return key press as I suggested so don't want to add a 'weird hack' feature to change something that I think may be covering up some other issue and could get you or others into other problems. Can you share an actual (simplified if possible) program that shows the issue I can reproduce, using the WaitForReturnKey subroutine below. Code: GraphicsWindow.Show() Another way to do it: Code: GraphicsWindow.Show() And another: Code: GraphicsWindow.Show() RE: GraphicsWindow.LastKey - jrmrhrb00 - 01-15-2025 LitDev, Here's the program. GPVC238.000. Once started. Type the number of seconds you want it to run. When it finishes you will see a box for "again" click it. The problem is it runs straight thru. If you look at the TW it will show the return key twice. The second time thru it should stop in the wait loop to allow for inputting seconds. JR RE: GraphicsWindow.LastKey - litdev - 01-15-2025 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! RE: GraphicsWindow.LastKey - jrmrhrb00 - 01-15-2025 LitDev, You are so good at this stuff. I have spent days, and you have spent minutes. Amazing! I really didn't want to give you the program as it was for the hourglass challenge. Now, I'm glad that I did because I would have never figured it out! So, with the LDTextWindow.SendKey(GraphicsWindow.Title,"Space" the GraphicsWindow has to have focus and the problem was I had it on the textbox? So, I know I can remove it from there, but how do you get it back to the GraohicsWindow? You can only set focus on shapes. Originally I never even thought about the LDTextWindow.SendKey function. Learn something new every day! Thaks for helping! You should be a teacher. JR RE: GraphicsWindow.LastKey - litdev - 01-15-2025 I don't think there is currently a way to set focus on GW, but there are other ways to get the Return key without Lastkey/SendKey. Here is another one: Code: GraphicsWindow.Show() |