The next time it happens, unplug the mouse. If the system hasn't locked (which is what Detrius is checking for) and the mouse cable is the problem, then unplugging the mouse should free up the keyboard again.
Also, try unplugging both, then plug just the keyboard back in. The mouse cable gets flexed more than any other cable, eventually they all fail. Eventually can be a good many years, depending on usage.