Greetings,
Welcome to the forum.
I am not a HP employee.
This is a tough one to solve.
Running HP diagnostics is good to do but this action may not be able to solve the problem. The hardware is good if diagnostics passed.
TouchSmart 520 gives many possible iterations. I can't isolate your specific product number.
I would think about when this symptom started and try installing the HP factory image.
This action (installing the factory image) requires backing up data before doing this.
Regards