Author Topic: Attention Wiki-teers. _EXIT  (Read 2053 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Attention Wiki-teers. _EXIT
« on: January 25, 2021, 11:53:46 am »
It's been about 8 years since I used this feature, and apparently, back then, it did not trap Alt + F4 (The Windows key combo that kills an active window.) I have QB64 v 1.3, and in my version it does trap that event, perfectly. However, the Wiki gives no mention of this. Of all the other various ways to trap keys, INP(96), _KEYDOWN, PEEK(1024), INKEY$, and _KEYHIT, I'm inclined to believe the _EXIT statement is the only way to trap Alt + F4. Any disagreement here?

In this one example, note that _EXIT saves the day, as the ON KEY statement fails to trap the Alt + F4 key press combo...

Code: QB64: [Select]
  1. KEY 15, CHR$(8) + CHR$(62) ' Scancode for alt + F4.
  2. ON KEY(15) GOSUB alt_F4_trap ' User defined key press.
  3. KEY(15) ON ' Event trapping on.
  4. PRINT "Press Alt + F4 for terminate warning."
  5.     _LIMIT 30
  6.     IF _EXIT THEN CALL exit_warning
  7.     b$ = INKEY$
  8.     IF LEN(b$) THEN PRINT b$: IF b$ = CHR$(27) THEN END
  9.  
  10. alt_F4_trap:
  11. PRINT: PRINT "Alt + F4 was pressed."
  12. CALL exit_warning
  13.  
  14. SUB exit_warning
  15.     PRINT: PRINT "Save changes before exiting?"
  16.     SLEEP
  17.     SYSTEM
  18.  

So if you run the example, you can see that only _EXIT traps the Alt + F4 event. I think if someone is up to it, with Wiki account rights, this should be included in the Wiki for all key statements, and especially for _EXIT, which was apparently updated some time past 2018. Thanks to whomever for that, great addition! Oh, if you have posting ability at Stackoverflow, you might want to amend that thread, as well... https://stackoverflow.com/questions/49567587/trap-alt-f4-in-qb64

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/