Keyboard doesn't work from time to time
From time to time, the keyboard stops working properly out of nowhere. I'm working on my mac and it simply switches to a completely different layout and there's no way to switch back. I searched in the preferences and found the on screen keyboard to see what's going on and I'm attaching a screenshot of how the keyboard layout looks like when it breaks. Sometimes even restart doesn't help and I have to restart my laptop with command+R in order to bring it back to life. I already reinstalled the system from the startup disk twice so it's pretty fresh and it happens more frequently. Can this be a hardware issue? And if it's a hardware issue, how come even an external keyboard behaves the same?
MacBook Pro 13″, OS X 10.11