All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad, sallallaahu 'alayhi wa sallam, is His slave and Messenger.
This matter (mentioned in the question) is not necessarily due to being possessed by the Jinn and the like. These events should not be interpreted as such at the first glance because thinking about magic, evil eye, the Jinn, and the like may cause a person to experience many illusions. According to the Sunnah, dreams are classified into three categories, as stated in the Hadeeth narrated by Imaam Muslim on the authority of Abu Hurayrah, may Allaah be pleased with him, that the Prophet said: “There are three categories of dreams: a good vision which is a glad tiding from Allah, a saddening dream from the devil, and a reflection of one's inner thoughts; so if any of you sees a dream which he does not like, he should get up and offer prayer and he should not relate it to the people.” [Muslim]
This means that Satan may have a role in one’s dreams to cause him sadness. Dreams could also be a reflection on things a person thinks about whilst awake. The Sunnah has underlined the Islamic etiquette to be followed by a Muslim upon seeing a disturbing dream: he should seek refuge with Allah, The Exalted, from the Accursed Satan, spit on his left side, and should not tell anyone about the bad dream he saw, for it will not harm him. The Hadeeth in this regard was authentically reported in Saheeh Al-Bukhaari and Saheeh Muslim.
As for a good vision, a person should rejoice at seeing it and relate it to those whom he loves and who wish him well; he should not tell everyone about it.
As for imagining things whilst awake and when closing one’s eyes, then this is normal. It is a reflection of the things that one has been through during the day, and it happens a lot.
Finally, we would like to explain that if someone believes that what is happening is due to abnormal reasons, and fears the possibility of some sort of possession by the Jinn, for example, then he should recite the Ruqyah, Thikr, and the Quran; for this is useful in all cases. Furthermore, he should perform ablution before going to bed and recite the reported Thikr before sleeping.
We ask Allah, The Exalted, to bless you with wellness and safety from all evils and afflictions.
For more benefit on how to interpret dreams skillfully, please refer to Fatwa 340525.
Allah knows best.