SavinaRoja / PyUserInput

A module for cross-platform control of the mouse and keyboard in python that is simple to install and use.
GNU General Public License v3.0
1.07k stars 244 forks source link

Xlib.error.DisplayNameError: Bad display name "" #79

Open tedtramonte opened 8 years ago

tedtramonte commented 8 years ago

Hi, I'm trying to use PyUserInput to translate pyOSC inputs into keyboard events for the purpose of controlling Emulationstation on a Raspberry Pi from an iPhone using the touchOSC app. The pyOSC code I have written works, but when adding PyUserInput code to my script, I get the following error:

Traceback (most recent call last):
  File "GBA_OSC.py", line 10, in <module>
    kbrd = PyKeyboard()
  File "/usr/local/lib/python2.7/dist-packages/PyUserInput-0.1.9-py2.7.egg/pykeyboard/x11.py", line 41, in __init__
    self.display = Display(display)
  File "/usr/lib/pymodules/python2.7/Xlib/display.py", line 83, in __init__
    self.display = _BaseDisplay(display)
  File "/usr/lib/pymodules/python2.7/Xlib/display.py", line 65, in __init__
    apply(protocol.display.Display.__init__, (self, ) + args, keys)
  File "/usr/lib/pymodules/python2.7/Xlib/protocol/display.py", line 44, in __init__
    name, host, displayno, screenno = connect.get_display(display)
  File "/usr/lib/pymodules/python2.7/Xlib/support/connect.py", line 65, in get_display
    return mod.get_display(display)
  File "/usr/lib/pymodules/python2.7/Xlib/support/unix_connect.py", line 59, in get_display
    raise error.DisplayNameError(display)
Xlib.error.DisplayNameError: Bad display name ""

Here's an excerpt of my script. Creating the object is literally the only PyUserInput code I have in it so far.

from OSC import OSCServer,OSCClient, OSCMessage
import sys
from time import sleep
import time
import types
import os
import RPi.GPIO as GPIO
from pykeyboard import *

kbrd = PyKeyboard()

Can anyone shed some light on this? I'm extremely new to Linux, Python, and GitHub, so this might not even be a PyUserInput issue.

Duality4Y commented 8 years ago

this code runs on you pi? and your pi is running X right? Because I think it can't find a display for X.

pepijndevos commented 8 years ago
                                                                                  You can use xvfb if your pi is running headless.                                                                                                                                                                                                                                                                                                                                        Sent from my BlackBerry 10 smartphone.                                                                                                                                                                                                                From: RobertSent: maandag 28 december 2015 3:17 PMTo: SavinaRoja/PyUserInputReply To: SavinaRoja/PyUserInputSubject: Re: [PyUserInput] Xlib.error.DisplayNameError: Bad display name "" (#79)this code runs on you pi? and your pi is running X right?

Because I think it can't find a display for X.

—Reply to this email directly or view it on GitHub.

tedtramonte commented 8 years ago

@Duality4Y Without the PyUserInput code, the script runs fine. I have it print out an idle message as well as the input values of every input from touchOSC and every value gets printed as expected.

@pepijndevos It was connected to a monitor using HDMI at the time, but I was running commands using Putty so I didn't have to switch sources constantly. Just now tried running the script directly on the Pi and got the exact same error.