Mac Wireless Keyboard - random key presses, possessed
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.