This can lead to race conditions. When synchronizing virtual keyboard state, just set a variable in UI thread. The variable will be read in worker thread during event polling, this will ensure that graphics code is configured at a proper time.