Hi Gerald, my advice is try replacing the keyboard.
I had this problem and have spent weeks trying to fix it, using every suggested fix on every forum I could find. I did endless PRAM and SMC resets, installed smc fancontrol, uninstalled and reinstalled Yosemite. Every fix failed. In fact it just got worse.
My 2008 imac had become virtually unusable. As soon as it powered up the screen went black, and it sometimes got stuck in a loop of trying to restart and would only stop if I unplugged the machine from the wall.
Then I read that someone had fixed this by replacing the keyboard. I had nothing left to try, so tried it.
It worked. Everything is back to normal. No screen glitches at all. It's like a miracle cure.
I hope it works for you too :)