The program only wants to run once . . . - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: The program only wants to run once . . . (/showthread.php?tid=2896) |
RE: The program only wants to run once . . . - Pete - 07-31-2024 I'd recommend changing _DELAY 2 to SLEEP 2. SLEEP should correctly pick up the key buffer input. Well, I actually recommend doing the whole routine in a proper loop fashion and setting a timer, as someone else, of mediocre significance, had previously mentioned. Pete RE: The program only wants to run once . . . - Jack - 07-31-2024 the following code as suggested by Steve works most of the time but every now and then it simply prints -13 Code: (Select All)
Pete sleep doesn't work, it doesn't catch the key RE: The program only wants to run once . . . - Pete - 07-31-2024 @Jack Good to know. SLEEP does work with INKEY$, but it has to be before the INKEY$ statement. _KEYHIT will not return a key value after either _DELAY or SLEEP. Code: (Select All)
Of course putting a SLEEP statement in has its advantages/disadvantages with a timing condition, as SLEEP (anything) is disengaged the moment a key is pressed, unlike _DELAY, which waits the full coded time before proceeding. There are just a couple of instances that I would prefer using _KEYHIT and Since I don't use SLEEP in my programs, that would never be an issue. For me it's a familiarity issue. Coding with INKEY$ is super fast, almost completely intuitive. With _KEYHIT I have to keep guessing what the hell key it is when reading the code. Pete - I think the Dems are trying to scare us, first with Biden now with Harris. RE: The program only wants to run once . . . - DSMan195276 - 07-31-2024 (07-30-2024, 10:34 PM)Kernelpanic Wrote: Again:I might have an idea, do you start the program by hitting F5? If you hold the F5 key too long then the release event of F5 will go to the newly started program, that would trigger the behavior you're describing since the F5 release will be returned by _KeyHit first before the spacebar. @Jack do you start the program by hitting the enter key on the 'Start' menu entry? -13 is an Enter key release event. RE: The program only wants to run once . . . - RhoSigma - 07-31-2024 (07-31-2024, 04:18 AM)DSMan195276 Wrote: I might have an idea, do you start the program by hitting F5? If you hold the F5 key too long then the release event of F5 will go to the newly started program, that would trigger the behavior you're describing since the F5 release will be returned by _KeyHit first before the spacebar. That can't be the case as Steve added a release wait loop in PR #399 to avoid the program is started before F5 is released. That was back in v3.10.0, no idea what version KP is using though. RE: The program only wants to run once . . . - Kernelpanic - 07-31-2024 (07-31-2024, 04:18 AM)DSMan195276 Wrote:It's the F5 key! I only press the key briefly, but here it has to happen in a flash. Yes, then it works. Is there any way to change this behavior?(07-30-2024, 10:34 PM)I might have an idea, do you start the program by hitting F5? If you hold the F5 key too long then the release event of F5 will go to the newly started program, that would trigger the behavior you're describing since the F5 release will be returned by _KeyHit first before the spacebar. Wrote: @RhoSigma, I always use the latest version. RE: The program only wants to run once . . . - Jack - 07-31-2024 @DSMan195276 I made the executable by pressing F11 and then opened a command window and execute the program, after the first run I used the up-arrow to show the history and then press return key RE: The program only wants to run once . . . - SMcNeill - 07-31-2024 (07-31-2024, 09:23 AM)RhoSigma Wrote:(07-31-2024, 04:18 AM)DSMan195276 Wrote: I might have an idea, do you start the program by hitting F5? If you hold the F5 key too long then the release event of F5 will go to the newly started program, that would trigger the behavior you're describing since the F5 release will be returned by _KeyHit first before the spacebar. This would only trap if someone was starting the program via the IDE. If you're starting it from the compiled EXE, then you could still carry over keypresses and such, if your keyboard has the proper repeat rates and such, and you hold whatever key you use to start it too long at start up. The best way I know to try and avoid stray junk from previous input messing up current input, is to place a _KEYCLEAR statement in the program before you go to fetch the new buffer, such as perhaps: Code: (Select All) Dim As Integer x RE: The program only wants to run once . . . - DSMan195276 - 07-31-2024 (07-31-2024, 09:23 AM)RhoSigma Wrote: That can't be the case as Steve added a release wait loop in PR #399 to avoid the program is started before F5 is released. That was back in v3.10.0, no idea what version KP is using though.Looking at it now, are we sure Steve's code works as intended? The code is this: Code: (Select All)
This isn't waiting for an F5 key release, it's just waiting for _KeyHit to return zero. That can happen while the F5 key is still held since _KeyHit only reports the press event once and then zero afterward (it will eventually start reporting the repeat key events but there's a delay before that happens). It's interesting because it does still fix the original issue, F5 does not spam out copies of your program anymore. I wonder if the forced _Limit 15 is what actually fixes it, once the new program finishes starting up it gains focus and keypresses stop going to the IDE (at least on my computer), so maybe the _Limit 15 is really just acting as a short wait for the program to start. RE: The program only wants to run once . . . - Kernelpanic - 07-31-2024 Quote:SMcNeill -The best way I know to try and avoid stray junk from previous input messing up current input, is to place a _KEYCLEAR statement in the program before you go to fetch the new buffer, such as perhaps:I just tried using _KEYCLEAR, but unfortunately there was no change; at least not for me. The F5 key has to be pressed like a lightning strike. Normally I have no problem pressing the F5 key. So far there have only been two problems with it: now and about a year ago. I had forgotten about it. |