Key-recognition and cursor-position updating are low priority operations. Sometimes failure to respond to key presses or failure (or slowness) in cursor-position updating can be used by lack of spare CPU cycles. Activity Monitor > CPU can be used to check fo any process monopolizing the processor (called a "runaway process).
Another potential issue for keyboards is the use of their "convenience" USB outlets for other devices. The only use for the second USB port on a keyboard is to allow the use of a low-power mouse, and adding anything else can exceed the power budget for the USB port and cause the keyboard to malfunction.
The power budgets for keyboards are quite tight, and using one or more USB extension cables can also cause keyboard malfunction. The Apple keyboard extension cable is remarkably short and deliberately keyed so that no more than one such cable can be used.