Posts: 2,698
Threads: 327
Joined: Apr 2022
Reputation:
217
(06-05-2023, 09:17 PM)SMcNeill Wrote: (06-05-2023, 09:09 PM)bplus Wrote: Looks allot like my demo
https://qb64phoenix.com/forum/showthread...1#pid16301
It is about the simplest way to implement _EXIT into a program. Great minds think alike.
I'll do one later to cover the ON TIMER version, but it's really not much different. I'd bang it out real fast now, except I have company otw anytime now and need to cut up some watermelon and cantaloupe for their kids to enjoy outside while the rest of us do our own things. As I promised above, here's the same example as what I'd used before -- but it's based off a simple ON TIMER event:
Code: (Select All)
_Title "_Exit Demo by Steve"
Dim Shared a As _Integer64
If _Exit Then System 'If you've clicked the exit button before we've did
' anything more than display a screen and a title,
' let's just give up and quit early and call it a day!
' The whole point to this early call to _EXIT is to disable the auto-exit and just
'to let our program know that we're going to manually be checking for it from now on.
MyTimer = FreeTimer 'Get a timer handle
On Timer(MyTimer, 0.2) Shutdown 'Set the frequency that they timer should repeat
Timer(MyTimer) On 'Turn that timer on
Do 'a main loop to do whatever we want
Cls
a = a + 1
Print "Whee! I'm ah counting! "; a
_Limit 100 'I'm going to count 100 counts per second.
Loop 'and I'm going to run forever and ever and ever and ever (as long as no one exits the program)
Sub Shutdown
If _Exit Then 'Check the exit condition when according to the timer interval
Print
Print "Oh nos! You have found my weakness and shut me down after I have ah only counted ta"; a
a$ = "This is the end of ah me!"
For i = 1 To Len(a$)
Print Mid$(a$, i, 1); "..";
_Delay .2
Next
_Delay 2
Beep
Print "And now I is ended!"
System
End If
End Sub
Posts: 346
Threads: 24
Joined: Jul 2022
Reputation:
20
ON _EXIT GOSUB season's fruit
Season's fruit:
strawberry
cherry
peach
apricot
watermelon
cantaloupe
grape
RETURN
Posts: 346
Threads: 24
Joined: Jul 2022
Reputation:
20
06-07-2023, 09:31 AM
(This post was last modified: 06-07-2023, 09:32 AM by TempodiBasic.
Edit Reason: miss to include the code
)
Hi
a little question to you QB64 friends...
I am not able to find key BREAK on my notebook keyboard... (I only found Canc, Stamp, Ins, Esc)
Should you run my little demo on your PC/notebook to test the Ctrl+Break option?
Code: (Select All) foo = _Exit
Print "Welcome to the _EXIT test code!"
Print "Please press X on the window bar or / and Alt+F4 on keyboard or Ctrl+Break on keyboard and look at results"
Print "press Spacebar to quit program"
View Print 5 To 20
While kb <> 32
kb = _KeyHit
_Delay 2
food = _Exit
On food GOSUB X, AltF4, CtrlBreak, XCtrlBreak
Wend
End
X:
Print "You have clicked on X of the window"
Return
AltF4:
Print "You have pressed Alt + F4 on keyboard"
Return
CtrlBreak:
Print " You have pressed Ctrl+ Break on keyboard"
Return
XCtrlBreak:
Print "You have pressed Ctrl+Break on keyboard and you have clicke on X of the window"
Return
Thanks
Moreover pressind Alt + F4 (Windows command to close the program) _EXIT retruns 1. Is It right?
Thanks for answers and testing.
Posts: 76
Threads: 19
Joined: Apr 2022
Reputation:
5
(06-07-2023, 09:31 AM)TempodiBasic Wrote: Hi
a little question to you QB64 friends...
I am not able to find key BREAK on my notebook keyboard... (I only found Canc, Stamp, Ins, Esc)
Should you run my little demo on your PC/notebook to test the Ctrl+Break option?
Code: (Select All) foo = _Exit
Print "Welcome to the _EXIT test code!"
Print "Please press X on the window bar or / and Alt+F4 on keyboard or Ctrl+Break on keyboard and look at results"
Print "press Spacebar to quit program"
View Print 5 To 20
While kb <> 32
kb = _KeyHit
_Delay 2
food = _Exit
On food GOSUB X, AltF4, CtrlBreak, XCtrlBreak
Wend
End
X:
Print "You have clicked on X of the window"
Return
AltF4:
Print "You have pressed Alt + F4 on keyboard"
Return
CtrlBreak:
Print " You have pressed Ctrl+ Break on keyboard"
Return
XCtrlBreak:
Print "You have pressed Ctrl+Break on keyboard and you have clicke on X of the window"
Return
Thanks
Moreover pressind Alt + F4 (Windows command to close the program) _EXIT retruns 1. Is It right?
Thanks for answers and testing. According to the wiki, alt-F4 should return 1. Break can be assigned different keypress depending on who built it. For Lenovo, which I use, it is Function-B to send a break command.
WHILE NOT EndOfLife(1)
HappyLife = HappyWife - (Money * Time * Travel * Gifts)
Kids = (NoTime * LackOfLove) MOD NumOfKids
IF Retirement <> Rich THEN YearsOnJob = YearsOnJob + 1 ELSE SeeTheWorld
WEND
Posts: 346
Threads: 24
Joined: Jul 2022
Reputation:
20
Oh my God!
Also you with Lenovo ideapad?
Well you are saying Fn+B = Ctrl+Break?
Ok I must correct my democode
Code: (Select All) foo = _Exit
Print "Welcome to the _EXIT test code!"
Print "Please press X on the window bar or / and Alt+F4 on keyboard or Ctrl+Break on keyboard and look at results"
Print "press Spacebar to quit program"
View Print 5 To 20
While kb <> 32
kb = _KeyHit
_Delay 2
food = _Exit
On food GOSUB X, CtrlBreak, XCtrlBreak ', AltF4
Wend
End
X:
Print "You have clicked on X of the window or pressed Alt+F4"
Return
'AltF4:
'Print "You have pressed Alt + F4 on keyboard"
'Return
CtrlBreak:
Print " You have pressed Ctrl+ Break on keyboard"
Return
XCtrlBreak:
Print "You have pressed Ctrl+Break on keyboard and you have clicke on X of the window"
Return
Now it works as expeted.
Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
(06-07-2023, 09:31 AM)TempodiBasic Wrote: Hi
a little question to you QB64 friends...
I am not able to find key BREAK on my notebook keyboard... (I only found Canc, Stamp, Ins, Esc)
Should you run my little demo on your PC/notebook to test the Ctrl+Break option?
On H.P. laptops like mine the following works: [CTRL][Fn][SHIFT].
Doesn't matter which CTRL key, but the SHIFT key has to be the one for your right hand -- the larger of the two. Usually that is marked as "pause" on top-left corner of the key. [Fn][Right-SHIFT] does like [SHIFT][@] on the Radio Shack TRS-80/Tandy Color Computer LOL. Yes that computer had a key left all to the at-sign.
Those key combinations don't always work on Linux however.
Posts: 3,979
Threads: 177
Joined: Apr 2022
Reputation:
220
(06-09-2023, 09:31 PM)mnrvovrfc Wrote: (06-07-2023, 09:31 AM)TempodiBasic Wrote: Hi
a little question to you QB64 friends...
I am not able to find key BREAK on my notebook keyboard... (I only found Canc, Stamp, Ins, Esc)
Should you run my little demo on your PC/notebook to test the Ctrl+Break option?
On H.P. laptops like mine the following works: [CTRL][Fn][SHIFT].
Doesn't matter which CTRL key, but the SHIFT key has to be the one for your right hand -- the larger of the two. Usually that is marked as "pause" on top-left corner of the key. [Fn][Right-SHIFT] does like [SHIFT][@] on the Radio Shack TRS-80/Tandy Color Computer LOL. Yes that computer had a key left all to the at-sign.
Those key combinations don't always work on Linux however. My windows 10-64 HP has "pause" in upper left of right hand shift key.
I will try that with Ctrl + with TempodiBasic code:
OK ctrl+fn+pause does ID exit correctly BUT! TempodiBasic's program wouldn't let me go with spacebar.
Too long a _delay also.
So here is still another b+ mod to make things better
Code: (Select All)
foo = _Exit
Print "Welcome to the _EXIT test code!"
Print "Please press X on the window bar or / and Alt+F4 on keyboard or Ctrl+Break on keyboard and look at results"
Print "press Spacebar to quit program"
View Print 5 To 20
While _KeyDown(32) = 0
kb = _KeyHit
'_delay 2
food = _Exit
On food GOSUB X, CtrlBreak, XCtrlBreak ', AltF4
_Limit 30
Wend
Print "You have successfully exited main loop and quit, thanks to bplus mod!"
End
X:
Print "You have clicked on X of the window or pressed Alt+F4"
Return
'AltF4:
'Print "You have pressed Alt + F4 on keyboard"
'Return
CtrlBreak:
Print " You have pressed Ctrl+ Break on keyboard"
Return
XCtrlBreak:
Print "You have pressed Ctrl+Break on keyboard and you have clicke on X of the window"
Return
b = b + ...
Posts: 346
Threads: 24
Joined: Jul 2022
Reputation:
20
@Bplus
on my Lenovo with your mod I never am able to get XCtrlBreak option.
_LIMIT 30 is too short on my notebook for performing the 2 actions: click on X and press Fn+B keys!
How modify framepersecond value to fit it to different CPU?
Posts: 98
Threads: 1
Joined: Jun 2023
Reputation:
3
bplus, your "another b+ mod" works great with my Dell laptop. I used: / and ALT+F4 to exit.
Posts: 3,979
Threads: 177
Joined: Apr 2022
Reputation:
220
06-17-2023, 02:29 AM
(This post was last modified: 06-17-2023, 02:35 AM by bplus.)
(06-17-2023, 12:18 AM)TempodiBasic Wrote: @Bplus
on my Lenovo with your mod I never am able to get XCtrlBreak option.
_LIMIT 30 is too short on my notebook for performing the 2 actions: click on X and press Fn+B keys!
How modify framepersecond value to fit it to different CPU?
Well we have quite a difference of 2 secs in your original code and 30 times a second in mine.
2 secs was much too slow a response time, in anyone's system I would imagine?
I imagine the _Limit number would fit any keypress response needed in the real application we are testing for here.
BTW how did you get from foo to food? were you hungry because you had spaghetti on your mind?
Update: Oh hey! I tagged myself by quoting Tempodi's tag on me! LOL
b = b + ...
|