If the contract has been ratified (all parties agree, sign, initial and deliver) then your check must be deposited within 48 hours by law. To get it back you can cancel the contract under one of the contingencies. The first one is usually home inspection. You don't really have to give a reason, just have your agent stop it under that contingency and your EMD can be returned after both parties sign a release.
If it's a condo, then you can cancel under the condo resale documents contingency. Again, no reason need be given.
If you've gone past the first ones, then you will have to rely on one of the other contingencies such as financing. If your financing cannot be completed - for any reason - then you can cancel under the financing contingency.
Where your EMD can be lost is, if you are past all your contingencies and you default on the contract, ie: fail to perform or go to settlement. If that's the case, then you can lose your EMD funds. If you are having a hardship such as family emergency, health issues, loss of income, etc. then the seller could let you out of the contract - if they want to - and your EMD could be released back to you. In that case though, it's up to the seller if they want to give you the EMD back.
Hope this helps.