See the instructions in this video

Additional steps for a newer macOS:

Open System Preferences > Security & Privacy > Privacy tab

Unlock the padlock at the lower-left with an admin username and password

Click on Input Monitoring

Open a Finder window and locate the file shown below

Drag-and-drop that file into the right side of the Privacy tab if it's not already there and make sure its box is checked

Then click on Accessibility and drag-and-drop the same file into that section and make sure its box is checked