// If the eventQueue can't be retrieved, the thread gets interrupted,
// or the thread isn't a instanceof EventDispatchThread then return
// a null as we won't be able to trap events.
try {
if (EventQueue.isDispatchThread()) {
EventQueue eq = null;
// Find the eventQueue. If we can't get to it then just return
// null since we won't be able to trap any events.
try {
eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
} catch (Exception ee) {
debug(ee);
}
// Safe guard
if (eq == null) {
return null;
}
int eventNumber = -1;
// Process the events until an object has been selected or
// the context-sensitive search has been canceled.
while (true) {
// This is essentially the body of EventDispatchThread
// modified to trap context-senstive events and act
// appropriately
eventNumber++;
AWTEvent event = eq.getNextEvent();
Object src = event.getSource();
// can't call eq.dispatchEvent
// so I pasted it's body here
// debug(event);