With my lens (24/2.8 STM), the focus position counter also resets during autofocus, so it's not really helpful. However, since this lens uses focus by wire, it is possible to build statistics on the manual focus movements.
The cleanest way to catch such events would be IMO with a property handler (which is fired very soon after receiving a message from the
MPU - which sends the lens position periodically, among many other things), but it does have to wait for DryOS to switch to the PropMgr task - so this method will give some additional delays. It is possible to use property handlers in Lua, but I prefer using plain C here.
If these delays (from DryOS multitasking) are interfering with the result, it is possible to hook the mpu_recv routine (see the dm-spy-experiments branch) and get the position as soon as it reaches the main CPU.
If the delays are still unacceptable, and you want to check the encoder status as soon as it's updated, understanding the MPU code (TX19A on some models, unknown on others) would be the only way to go. That alone can easily take months of full-time work (or years, for a project done in nights and weekends), but it's doable (there is documentation available from Toshiba, and there are also emulators for similar - but not identical - microcontrollers).