Why don't you simply ignore the keys when a flag is raised? I mean: when you start your task, you set a flag to true. While this flag is set, you ignore all key strokes (you only return true in the event handler). When the task ends, you set the flag to false to reenable the key handling.