Thanks for an absolutely fantastic question! This is such an interesting area of research at the moment and there are several ways they can work, but the simplest actually uses the technology I use to measure children’s electrical brain activity (electroencephalography, EEG for short). The way that people are designing systems for the brain to control computers at the moment is that they train the computer on the patterns of electricity produced when people think certain things (they used to train people to produce certain patterns of activity instead, but that was hard). For example if you want to make a dot to move up on the computer screen then you start by thinking up and train the computer on the difference in your activity patterns measured on sensors over your head when you were thinking up and when you were resting (thinking about anything else, but not up).
However, this equipment is still very basic, because there is a limited number of patterns your brain can produce on your head with a small number of sensors, we can increase the number of sensors but eventually we would run out of sensors and we would also end-up having to have lots and lots of training for the computer to know what pattern meant what.
If we really want to control computers with our brains we are probably going to have to put sensors into the brain and have a way of plugging ourselves in, like in the matrix. I think it would be worth it to be able to control computers just by thinking about it! What do you think?