My MacBook Pro (mid 2014, Sierra 10.12.1) sometimes gets stuck after waking up after sleep. Some key seems to have stuck and keeps pressing into the password field forever, filling the password field and making me unable to type anything in. If I select all/delete, it refills again immediately, just like I'm pressing and holding a key on the keyboard. I've pressed all the keys as maybe OS thinks one is stuck, hoping that it will fix, but pressing all keys didn't work either. The only solution for me is to restart (and even if I press esc to sleep again, it immediately wakes up in a second as its "pressing" a key), if I close the lid, wait a minute, and open it again, it's still the same.
If I restart, I lose the work inside my apps. Usually nothing serious, but sometimes I've got apps open doing work in the background etc (e.g. batch image processing, neural net training, or any stuff that I can't save properly until the end) and they are all gone. This happens rarely, but when it happens, it causes me to lose data.
Why would this happen and how can I prevent this?