DAY 004: _WINDOWHASFOCUS
#1
A keyword which simply tells you if your program is topmost and has focus in your OS.  For those who don't understand what I'm talking about with topmost, let me give you a simple example:

1) Open your file explorer and click the qb64pe icon and start up a fresh instance of the IDE.  It'll pop up on your screen on top of any other windows which you may have open -- your browser, the file explorer, and whatever else was open on your desktop.  At this point, it's the *topmost* program on your screen, and it has focus.  When you hit keys on the keyboard, you'll be typing into the IDE and not your web browser.

2) Now, click on your file explorer once more and open notepad.  Start typing with the keyboard and watch as the letters appear in the notepad text area, rather than in QB64's IDE.  Notepad is now the topmost program and has focus, so QB64 has lost it.

Now let's say you have a program that you might want to respond differently, regarding whether it has focus or not.  How do you detect whether your program is the focus of the user, or not?

With _WINDOWHASFOCUS.  (Well, at least for Windows and Linux users.  The keyword is not yet supported on MAC, according to our wiki currently.)

Example from the wiki:
 
DO
    IF _WINDOWHASFOCUS THEN
        COLOR 15, 6
        CLS
        PRINT "*** Hi there! ***"
    ELSE
        COLOR 0, 7
        CLS
        PRINT "(ain't nobody looking...)"
    END IF
    _DISPLAY
    _LIMIT 30
LOOP


A simple example, where the program will PRINT "*** Hi there! ***" on the screen if the window has focus, and will print "(ain't nobody looking...)" when it doesn't.

QB64 Wiki Entry: _WINDOWHASFOCUS - QB64 Phoenix Edition Wiki
Reply


Messages In This Thread
DAY 004: _WINDOWHASFOCUS - by SMcNeill - 11-09-2022, 01:26 PM
RE: DAY 004: _WINDOWHASFOCUS - by bplus - 11-09-2022, 04:42 PM
RE: DAY 004: _WINDOWHASFOCUS - by SMcNeill - 11-09-2022, 06:25 PM
RE: DAY 004: _WINDOWHASFOCUS - by mnrvovrfc - 11-09-2022, 06:28 PM
RE: DAY 004: _WINDOWHASFOCUS - by Pete - 11-10-2022, 12:00 AM
RE: DAY 004: _WINDOWHASFOCUS - by SMcNeill - 11-10-2022, 12:35 AM
RE: DAY 004: _WINDOWHASFOCUS - by Pete - 11-10-2022, 01:20 AM
RE: DAY 004: _WINDOWHASFOCUS - by SMcNeill - 11-10-2022, 02:17 AM
RE: DAY 004: _WINDOWHASFOCUS - by CharlieJV - 11-10-2022, 12:53 AM
RE: DAY 004: _WINDOWHASFOCUS - by Pete - 11-10-2022, 02:24 AM



Users browsing this thread: 7 Guest(s)