The large pins (0,1,2) and the logo (V2 only) on the micro:bit can be configured to know when they are being touched or pressed. The micro:bit V2 is also able to use a different touch mode, which you are able to configure in your program.
Resistive touch (default for the large pins 0, 1 and 2)
Resistive touch works by detecting a change in resistance when an electrical signal is passed through a conductive material as part of a circuit.
Humans are, in fact, a conductive material, so for example, when you touch a numbered pin on the micro:bit with one finger and touch the GND pin with another finger you will complete a circuit that an electrical signal can flow through.
Each of these large pins has a weak pullup resistor connected to it, which means that by default the pin is pulled up to a voltage of 3V and when it is touched the pin is pulled down to GND or 0V. This is similar to how a button press works.
Capacitive touch (default for the logo) V2 only
Capacitive touch works by sensing changes within the electric field of a capacitor using a finger as a conductor. It will trigger as your finger touches the pin or gets very near. Capacitive touch does not require you to make a ground connection as part of a circuit, so you can just touch the micro:bit with one finger.
Setting the touch mode (V2 only)
It is possible to change the default settings of resistive touch (default for the large pins 0, 1 and 2) and capacitive touch (default for the logo) in your program.
The set pin to touch mode block can be found in the PIns > … more > micro:bit(V2) toolbox
The set pin to touch mode API for MicroPython is yet to be implemented, you can see the status of this in this Github issue.
What is the difference between touched and pressed?
Depending on how you interact with the pin, you can trigger several different time-based events:
Touched is triggered as soon as a finger touches a pin.
Pressed is triggered when a finger is pressed down on a pin and then released up from it.
Released is triggered when a finger is released from a pin.
Long pressed is triggered if the pin is held down for longer than 1 second before being released.
Example: If you touch a pin and then release your finger from the pin you will trigger a touched event followed by a pressed and released event. This is similar to how keypresses are detected on a computer or phone keyboard.
Read more about the micro:bit events and how they are scheduled in MakeCode.