Tim Bowen discusses this versatile adverb.

Learners often imagine that hardly is related to the word hard and is its adverbial form. This leads to errors such as I work hardly, where the speaker presumably means the opposite of the structurally correct form I hardly work.

The word hardly is an adverb, however, and has three principal uses. Its main use is to say that something is almost not true or almost does not happen at all, as in She hardly spoke except to give her name or I was so busy I hardly noticed the time. In this sense, it is also used before words like ever and any (as well as words containing any, such as anyone, anything and so on) - for example, It hardly ever rains in this part of the world and Hardly anyone came to the party.

Hardly is also used to say that something had only just happened when something else happened, as in I had hardly opened the door when the telephone rang. In this sense, inversion is often used to give greater emphasis (especially in written English): Hardly had they reached the hotel than a crowd gathered outside (note the use of than rather than when in the inverted example). It can also be used when the speaker thinks that something is not true, not possible or not surprising, as in This is hardly the time to start discussing marriage or You can hardly expect people to like you if you talk to them like that.

Finally, in British English hardly is used as a negative response when someone has suggested something that is impossible: Are you hungry? Hardly. I only had breakfast half an hour ago!