Prompt [Q] Switch between desktop and metro settings

Hello peoples,

Basically, I want to be able to have it so when I have my surface keyboard flipped out, everything that can do so switches to desktop settings - so links are opened in desktop IE, and when you start it, it goes to desktop. But if you don't have the keyboard attached or it is flipped over the back (deactivated) then everything changes back to metro settings.

I was wanting to write a script for this, a lot of it should be straight forward, the hard part is detecting when the keyboard is deactivated.

Any help would be much appreciated.