Use more flexible scope-based flag setting.
Fix interactive console key processing.