Samuel Morse was a painter, not an engineer; the electromagnet that started it all belonged to someone else. But after hearing a lecture on the new electromagnetism in 1832, Morse spent years turning the idea into a telegraph — and, with his assistant Alfred Vail, into a code. The first version assigned numbers to words and looked them up in a dictionary; Vail's second version, built on letter frequencies, is the ancestor of what we use.
On 24 May 1844 Morse tapped the famous question over the wire between Washington and Baltimore. Within a decade telegraph lines were stitching countries together, and the code went with them.
National variants quickly sprouted — the original "American Morse" on landlines, Gerke's cleaner revision in Germany and Austria. When the world's telegraph administrations met in Paris in 1865, the Gerke lineage was adopted as International Morse, the code still in use (with tiny amendments) today.
Wireless telegraphy inherited the code, and in 1906 the Berlin
convention made ... --- ... the global distress signal — chosen
not as an abbreviation but as an unmistakable, easy-to-send rhythm.
Six years later the Titanic's operators transmitted it (alongside
the older CQD call) as the ship went down, and the world understood
what the dots were saying.
Commercial use declined through the twentieth century, but the sea kept Morse longest: navies and ships' radio officers tapped away until 1999, when the Global Maritime Distress and Safety System made satellite equipment the standard and ended Morse's official watch at sea. Amateur radio operators, aviation navaids and flashlights in prisoner-of-war camps keep it alive anyway.