Analyzing USB signals
There are ready made USB analyzers that operate as a pass through device. In other words a device like your keyboard plugs into the analyzer and then a cable from the analyzer connects to the computer. The analyzer has yet another connection cable that goes to a data logging host computer that captures, analyzes and saves the data. In many cases the data logging host computer can simply be yet another USB port on the same computer that the keyboard connects to.

It hardly makes sense to attempt to build such device when it can simply be purchased. If your answer is that you want to learn then simply get yourself some USB port analyzer software for your computer. If you say that you want to build this as some type of product in quantity then I would question the usefulness of such product other than nefarious use which would be highly discouraged.