No announcement yet.

Touchscreen from Python (without X)?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Touchscreen from Python (without X)?

    I've got the 4DPI-24-HAT working just fine playing videos on a Pi Zero W using and omxplayer, and my client loves it!

    While I could use the buttons as per the supplied Python code, they are hard to get to in the case I'm using, and I'd much rather use the touchscreen. Is there a way to read the touchscreen with Python code if X is not running? Even just registering "Something touched me!" that would let me use the entire screen as a button would be better than nothing...


  • #2

    Welcome to the forum,

    If this is the case, one way is using xdotool which can be found here: Simulate keyboard mouse events using xdotool raspberry pi

    Then, set the cursor location at (0,0) and when the current cursor location was changed, you could start a pop-up message.

    And also, subprocess will help you to execute a xdotool command within a python script.

    Hope it helps,

    Best regards,
    Last edited by [email protected]; 9 February 2019, 04:42 PM.


    • #3
      That's a lot of complexity, and I'm not sure how much of it'll work without X running (which it isn't in this case).

      Is there any way to interface to the touchscreen using Python on a device that isn't running X?



      • #4
        So I've gotten to the point where I can either:

        A) Read the buttons from Python, send a simple text UI to /dev/tty1, and play a video using omxplayer and


        B) Start X and set/read the cursor position using xdotool and (but I'm unable to play the video)

        But not both. I'd love to be able to add some kind of touch-screen interface to A) above, any chance of a Python (or C or command line) interface to the touchscreen without running X?



        • #5
          Hello wpns

          I have recently started experimenting with the touch interface from Python and without running X, on a gen4-4DPi-50CT-CLB screen.
          I found the pimoroni python-multitouch library in GitHub and I have modified it for the gen4-4DPi screen to use the evdev and asyncio Python modules for detecting the touch events.
          My code is still very much in beta, but you are welcome to try it out:

          The new 'driver' is called ep0510m09 and you can find it under the Library folder.
          I had no time to develop more examples nor to try it out with a real GUI (currently my screen is not working properly and I want to fix first the inverted colors issue).

          I hope it helps