

Task

Obtain a valid   Y   or   N   response from the keyboard.

The keyboard should be flushed, so that any outstanding key-presses are removed, preventing any existing   Y   or   N   key-press from being evaluated.

The response should be obtained as soon as   Y   or   N   are pressed, and there should be no need to press an   enter   key.




void local fn DoDialog( ev as long )
  CFStringRef key
 
  select ( ev )
    case _windowKeyDown
      cls
      key = fn EventCharacters
      select ( lcase(key) )
        case @"y",@"n"
          printf @"You pressed the \"%@\" key",key
          DialogEventSetBool(YES)// we handled the event
      end select
  end select
end fn
 
subclass
window 1, @"Press \"Y\" or \"N\" keys", (0,0,550,400)
 
on dialog fn DoDialog
 
HandleEvents