It might be possible to make a simple short-circuit signal between the keyboard top and bottom halves when opening/closing the keyboard. That would require adding an extra element in the i2c stream, besides the data from the keyboard, and I don't know if you can do that. If that can't be done, how about a special gesture on the keyboard to turn it on/off? I.e. double alt, or something?