Trying to identify a short science fiction story where the protagonist is some kind of policeman or investigator, and at the end he chooses to live his life out hooked up to some kind of virtual reality machine. The ending describes him having his eyelids removed as he is attached to the machine, and then as the machine starts working he "becomes" a cowboy or some other western figure riding his horse downhill in a desert scene.
This is "Spectator Sport," by John D. MacDonald, originally published in the Feb 1950 issue of Thrilling Wonder Stories, and the original from this magazine can be read online in its entirety courtesy of archive.org.
There is an (unaccepted) answer for a previous question with appropriate citations to show matching details. As mostly copied from that answer:
There are direct neural interfaces for virtual worlds...
"Permanent was so much better than the temp stuff you could get on the home sets. The nerve ends was what did it, of course."
People are "hooked up" via surgery...
"They rolled him over on his side, made the usual incision at the back of his neck, carefully slit the main motor nerves, leaving the senses, the heart and lungs intact. They checked the air conditioning and plugged him into the feeding schedule for that bank of Perms.
Next they swung the handrods and the footplates into position, gave him injections of local anesthetic, expertly flayed the palms of his hands and the soles of his feet, painted the raw flesh with the sticky nerve graft and held his hands closed around the rods, his feet against the plates until they adhered in the proper position."
Specific mention is made of the removal of eyelids...
"Back in the cubicle the technicians were making the final adjustments. They inserted the sound buttons in Rufus Maddon's ears, deftly removed his eyelids, moved his head into just the right position and then pulled down the deeply concave shining screen so that Rufus Maddon's staring eyes looked directly into it."
Finally, the Wild West scenario at the end:
"Inside the cubicle, Dr. Rufus Maddon was riding slowly down the steep trail from the mesa to the cattle town on the plains. He was trail-weary an sun-blackened. There was an old score to settle. Feeney was about to foreclose on Mary Ann's spread and Buck Hoskie, Mary Ann's crooked foreman, had threatened to shoot on sight.
Rufus Maddon wiped the sweat from his forehead on the back of a lean hard brown hero's hand."