I am looking for a short phrase that I can say when something bad happens. For example, when my mouse breaks or my computer is hanging.
I know the expression damn it but I need something more polite.
What you're looking for is a minced oath version of "damn it". You have many options.
If you want to stay as close as possible to "damn it", just without the objectionable "damn" in there, you can use almost any single-syllable word that starts with D. The most common are:
• dang it
• darn it
• dern it
If you just want an interjection you can use when things go awry, the possibilities multiply.
• shoot (instead of shit)
• shucks (instead of shit; though note that "oh shucks" has a different meaning than "oh shit")
• heck (instead of hell)
• gosh (instead of god)
• what the hey (instead of "what the hell")
• oh my lord (instead of "oh my god")
• fricking (instead of fucking)
• oh fudge (instead of "oh fuck")
There are also some expressions that aren't really a minced variant of anything more explicit, but are used in the same sorts of situations. The one that comes to mind is "oh dear", but the stereotypical southern grandma could probably list a lot more.
'Bugger' is used a lot in this corner of the world (Australia/NZ). It is probably about the same 'politeness level' as damn it (and was even the running gag word in a nationally shown Toyota commercial) - though I expect this would be less so if people looked up the definition.
As the link shows, it is definitely used in the type of situations you describe.