some keys stop responding unexpectedly

i am using a magic keyboard which i got with my iMac late 2015 sometimes my keyboard's keys which include (0,p,esc,[,],\,- and the return key) stop working unexpectedly but they start working suddenly and after some time they stop working what would be the solution and may i please know the reason please

crwdns2934089:0crwdne2934089:0 crwdns2934093:0crwdne2934093:0

crwdns2934109:0crwdne2934109:0

crwdns2889612:0crwdne2889612:0 0
crwdns2934285:0crwdne2934285:0