אמר עם הספר ישוב מחשבתו הרעה “Achashveirosh commanded that they should write in a book, that he had retracted from his bad thoughts.” (Esther 9:25)
It’s brought down from the Gaon, that a segulah to be saved from bad thoughts during davening, is to look inside the siddur when davening. The above is hinted at in the aforementioned pasuk: אמר עם הספר – daven with a siddur, ישוב מחשבתו הרעה – then you will be saved from bad thoughts.