You can tell by the pronoun that's used. :D "du" is a subject pronoun meaning you, whereas "deg" is an object pronoun. If "deg" is used, that means "you" is receiving some sort of action, or it might come after a preposition. If "du" is used, on the other than, that means that "you" is the subject—it's doing the action.
- Hvem liker du? = Who do you like?
- Hvem liker deg? = Who likes you?
Hopefully this helps! ^_^