Mac Wireless Keyboard - random key presses, possessed As a tech guy, I am really baffled by what's going on with my keyboard. All search results point to the keyboard shortcut settings, but I have been hammering the "Set to Default" button in there, to no effect.

My keyboard is the Apple Wireless Keyboard, bluetooth with 2x AA batteries.
It has just turned 2 years old.

It all started with the ESC key that simply stopped working about a month ago. This was a few weeks before my warranty would expire, so I contacted the retailer, but they didn't want to provide any support, only suggesting I deliver both my keyboard AND MacBook to their repair center.

Maybe I would have done that, if I wasn't on the other side of the world. Now the warranty has expired, and problems are getting worse.

Could it be wireless interference? Some internal short circuit? Let me know if you know of anything similar.

What I have tried


Resetting Keyboard Shortcuts.
Toggling every Accessibility feature on and off again.
Changing Input Sources (keyboard layout).
Replacing batteries in the keyboard with a fresh pair of Duracells.
Remove pairing from MacBook and force re-pair.
Rename keyboard.
Boot my MacBook from a Linux USB. Keyboard is acting the same.


Other info


The issue has persisted through the upgrade to macOS High Sierra, but wasn't as bad before.
I do have a custom keyboard layout (made with Ukelele), and the issues started some time after that. However, I have tried switching and removing my custom keyboard layout (so none other than the default layout is enabled), makes no difference.
There seems to be nothing wrong with the built-in keyboard, it acts completely normal while the wireless keyboard is freaking out.
The only other bluetooth device I am using simultaneously is the Apple Magic Mouse - no issues there.
I have never spilled anything in the keyboard, or done it any harm - other than typing a lot, and hard.


Other symptoms

Typing the @ symbol (on my EU keyboard that's Alt + ') suddenly stopped working. Nothing happened, but without the Alt modifier, the ' key worked fine. And the Alt modifier was working fine with other keys as well. Sometimes the Audio Preferences randomly open up... 

Then one day I was typing my password, and not being able to log in. Seems my P has magically started turning Caps Lock on and off.

Lately the keyboard's ESC key is working again, and it feels like the keyboard is either working 100% or acting crazy 100%. Meaning, in the beginning of this post my S key would append - and SPACE a z when typing, and seconds later I can type a full sentence with no interference.
Since your built-in keyboard seems to work fine, I'd try to reset both the macOS Bluetooth Device List and Bluetooth Controller. 

IMPORTANT: This will reset all connected Bluetooth devices, including your Apple Magic Mouse, so your wireless keyboard and mouse will need to be reconnected.

Before commencing, you will need to have the Bluetooth icon showing in the menu bar. If it is not there, open System Preferences > Bluetooth and enable the option Show Bluetooth in Menu Bar.

Resetting the macOS Bluetooth Device List and Bluetooth Controller

Follow these steps:


Hold down both the Shift and Option keys and at the same time click on the Bluetooth icon in the menu bar. Once the menu is showing, release the keys.     
From the Bluetooth menu, choose Debug > Remove All Devices
Hold down both the Shift and Option keys again and at the same time click on the Bluetooth icon in the menu bar. 
From the Bluetooth menu,  choose Debug > Reset the Bluetooth Module
Restart your Mac
Setup your keyboard again
Setup your Magic Mouse again


Let us know whether this helps.