I have an idea that could solve this. Do the exact opposite as with mining. When you start an attack, remember where the attacker is. When the target is killed, check if the attacker moved and if not display a message "You did not learn anythin, as you did not move while attacking.". Or something.
Or make it so that you do not learn in full defensive mode, which is the default for being automatically attacked. (In cvs at least, not on laanx, I just checked

).
That may even apply for practicing armor. You do not need skill in your armor absorbing a blow. It can do that when putting it on the ground and hitting it. So, requiring that you move and are not full defensive seems OK for that too.
I even implemented the full defensive thing for weapons. It does not show a message (that would require some further checking in class skill). Exactly the same could be done in the same file for armor, but I am not so sure you could not practise in full defensive mode, as the system still makes you dodge and block.
Apply the following patch (to combatmanager.cpp, version 1.152):
526c526,527
< if (gemTarget->GetClientID() == 0 && !gemTarget->GetCharacterData()->IsPet())
---
> if (gemTarget->GetClientID() == 0 && !gemTarget->GetCharacterData()->IsPet()
> && gemAttacker->GetCharacterData()->GetCombatStance() != PSCHARACTER_STANCE_FULL_DEFENSIVE)
528c529
< // Successful attack of NPC, train skill.
---
> // Successful attack of NPC, and not in full defensive mode, train skill.