I have the Apple Magic Keyboard model A1644, which was released in 2015:
Both this and the Magic Trackpad 2 have switches that allow you to turn it on (green) or off (white). I find that the switch on the trackpad works just fine. However, oftentimes when I try to turn off my keyboard and put it in my bag, I'll find out that the keyboard was on the entire time and draining my computer's battery due to random keystrokes being tapped. It's as though the hardware switch is broken or not respected by the keyboard.
Is there any way to shut off this keyboard and ensure it's shut off?