Tapping Morse code: Huh?

This is a common trope in films: The hero, incarcerated by the villain or otherwise trapped in an enclosed space, uses knocks to communicate with the outside world via Morse code. How is this supposed to work, assuming it was ever used in practice? Morse code consists of short signals (dots), long signals (dashes), and silence (pauses). When I knock a solid surface, it makes one singular tapping sound; I can’t control the length of the sound. Is it that the sender marks not the signal itself but the end of the signal, so that two knocks in quick succession mean a dot and two knocks with a longer break between them would mean a dash?

Yes: you can control the length of the pause.

I do not know Morse code, but I’m familiar with how it is portrayed as you describe in films. Basically, you leave a longer interval between the dashes than you do the dots. For example, SOS:

knock, knock, knock [pause]
knock… knock… knock [pause]
knock, knock, knock

That is also the way I understand it is done. And you don’t even have to tap, you can do it by blinking!

A tap code is not necessarily Morse Code:

As noted in that tap code article, another way to make dashes distinguishable from dots is to make the dashes louder.

One of my professors claimed to have done it, while imprisoned in the GDR around 1980. Him and other political prisoners communicated by sending Morse code through the heating pipes.

Good point.

In the early days of the US-Viet Nam war, US POWs improvised that code as described in the article. One or two people knew it from classical studies and they taught it to everyone else imprisoned at the time. Then it was taught to each newly arriving prisoner. Which teaching was itself a difficult task.

One of the many lessons that DoD learned from Viet Nam was the value in training at least aircrew, and some especially behind-the-lines ground troops, e.g. Special Forces, how to be a successful POW. And to have all the services teaching the same tricks, techniques and basic doctrine.

By the time I was going through USAF tactical pilot training ~10 years after US involvement in Viet Nam ended all that stuff was routine. Which was a real help in captivity.

Also, if you have an object you can use for tapping, instead of just your hand, I’ve seen tap and scratch codes. Tap for a dot, scratch for a dash.

Really, so long as you can distinguish two different signals, you can do Morse.

One of the books in the Wings of War series utilizes similar for sequences set in Hỏa Lò. The author has a POW passing messages with a push broom, alternating between sweeping and tapping.

That last sentence seems to imply that you were in captivity?

I was never an actual captive or POW. Sorry to be unclear.

However the services run a POW training program for aircrew which includes a few days of simulated captivity. Which everybody goes through. Not much more can be said by the participants, but see here for more: