I have some example code for using STM32F042 in USB HID mode.
Hey, would be awesome if you share it. I made a prototype with 32U4, but it's just too slow, I have to upgrade to STM32.
What I need from MCU:
USB support (HID keyboard)
7 fast switching regular digital outputs (not PWM)
5 regular digital inputs (optional - 5V tolerant)
I2C
Optional - 9 to 18 capacitive touch input pins
Optional - SPI
64k< program memory
48MHz<
~1K EEPROM (I noticed STM doesn't have EEPROM, so external IC for that is needed?)
If I can eliminate capacitive touch IC and replace 32U4 with STM32F103C8T6 it would be perfect.
BTW, to make STM32 "blue pill" as HID keyboard was waaaaaaay easier than I expected, it's as simple as burning a bootloader as described in a video below (burning bootloader is optional, I burn it cos I don't want to use FTDI) and using
USB Composite library for STM32F1, I don't know why but I thought it will be way harder to migrate to STM32. I should went with STM32 from the start... You live you learn

The last thing I need to finalize functionality of my software is to add multimedia keys support, but as I understand it's not a same thing as HID keyboard.