All perfect praise be to Allaah, the Lord of the worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
Adversities raise the rank of Muslims and expiate their sins. In a Hadeeth on the authority of Abu Hurayrah the Messenger of Allaah, sallallaahu ‘alayhi wa sallam, said that adversities would befall a Muslim, affecting himself, his property, and his children until he meets Allaah the Almighty on the Day of Resurrection without a sin. [At-Tirmithi and Ahmad]
What happened to you may be obsessive illusions or hallucinations due to psychological factors. On the other hand, it may be an attempt from devils to make you practice magic. Teaching or learning magic turns a Muslim into an apostate, according to the soundest opinion among scholars. Allaah the Almighty Says (what means): {It was not Sulaymaan (Solomon) who disbelieved, but the devils disbelieved, teaching people magic.}[Quran 2:102]
I advise you to ask Allaah the Almighty for protection. Allaah the Almighty is the ever-Powerful and the ever-Pervading who can protect you against the Devil. Allaah the Almighty Says (what means): {Say, "I seek refuge in the Lord of mankind, the Sovereign of mankind. The God of mankind, from the evil of the retreating whisperer— who whispers [evil] into the breasts of mankind— from among the jinn and mankind."}[Quran 114:1-6]
You should also observe the Athkaar (supplications and remembrance of Allaah the Almighty), because this is an effective protection against the Devil. You should also keep the company of righteous friends who will remind you of Allaah the Almighty if you forget and help you to do good deeds.
Those who abandoned you did not take the correct course of action. They should have helped you to do good acts and to overcome your adversity. By abandoning you, they are helping the Devil to harm you. I advise them to be pious and to fulfill the order of Allaah the Almighty. Allaah the Almighty Says (what means): {And cooperate in righteousness and piety, but do not cooperate in sin and aggression.}[Quran 5:2]
And Allaah Knows best.