If the verb is intransitive (ie there is no object), an adverb of manner is usually placed after the main verb. In literature or poetry it can also be placed before the verb at the start of the main clause.
The crowd cheered loudly as the band passed by. - correct
The crowd loudly cheered as the band passed by. - literary
Loudly the crowd cheered as the band passed by. - literary
If the verb only has an indirect object (ie there is a preposition between verb and noun, the adverb normally goes after the main verb, though it can also go at the end of the sentence: this is common when using a long adverbal phrase.
She stared intently at the mirror - correct
She stared at the mirror with great deliberation - acceptable if it's a long adverb phrase
she intently stared at the mirror - literary
Intently, she stared at the mirror - literary
When a verb has a direct object, you never put an adverb of manner between the verb and its direct object: instead, you put it at end of the clause, or before the verb.
The children ate greedily the cake as soon as it was placed on the table. - incorrect
The children ate the cake greedily as soon as it was placed on the table. - correct
The children greedily ate the cake as soon as it was placed on the table. - correct
Greedily, the children ate the cake as soon as it was placed on the table. - literary
Looking at your two sentences, carefully is placed before the verb for literary effect, and nervously is placed after the verb because this the is normal position for a verb with an indirect object (the window).