Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5934237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:05:10+00:00 2026-05-22T15:05:10+00:00

[SOLVED – Provided example contains the answer!] I am trying to implement a program

  • 0

[SOLVED – Provided example contains the answer!]
I am trying to implement a program which is started in fullscreen and does not allow any userinput (wether mouse nor keyboard) because it just reacts on UDEV-Signals, when a usb-stick or cd is inserted.
I want to prevent, that a user puts in a keyboard / mouse and does somethin weird with the workstation.
The only case, that a keyboard is needed, is when an administrator inserts a keyboard and presses CTRL-T, so my program opens a terminal-window.

I work with a Debian (Squeeze) + Gnome-Desktop-Environment.

I tried to use XLib, which works fine for grabbing all Keyboard-Events, but I cannot ungrab my keyboard, when my program opens my terminal (which works also perfectly), so the user cannot use the shell unless the keyboard-fetching is turned off.

here are some crucial code-fragments:

class ScanWSClient(gtk.Window):

   def __init__(self, url):
         # current display
         disp = Display()
         self.display = disp

         gtk.Window.__init__(self)           

         self.terminal_window = None
         self.kb_handler = KeyboardHandler(self).start()

         #self.fullscreen()

         self._browser= webkit.WebView()
         self.add(self._browser)
         self.connect('destroy', gtk.main_quit)

         self._browser.open(url)
         self.show_all()

class KeyboardHandler(threading.Thread):
   def __init__(self, scanws_client):
         super(KeyboardHandler,self).__init__()
         self.running = True
         self.daemon = True          
         self.terminal_window = None
         self.scanws_client = scanws_client #

   def run(self):
         root = self.scanws_client.display.screen().root


         while self.running:
                event = root.display.next_event()
                self.handle_event(event)
                time.sleep(1)

   def handle_event(self,aEvent):
                keycode = aEvent.detail
                state = aEvent.state
                key_type = aEvent.type

                if keycode == 28 and key_type == X.KeyPress:
                      if self.scanws_client.terminal_window == None:
                            self.scanws_client.terminal_window = TerminalWindow(self.scanws_client, "Administrative Shell started...Type  *exit* to return to the locked workstation")
                      else:
                            self.scanws_client.terminal_window.present()
                            self.scanws_client.display.flush() #THIS FLUSH IS NECESSARY TO UNGRAB THE KEYBOARD LATER ON!!!
                      self.scanws_client.display.ungrab_keyboard(1, X.CurrentTime) 
                      print "Key: %s / Mask: %s / Type: %s" % (keycode, state, key_type)

                print self.scanws_client.terminal_window

In my threaded KeyboardHandler, I fetch all xlib-queued events and check with my function “handle_event”, if there is CTRL-T pressed. If so, I open my terminal and ungrab my keyboard (doesnt work):

self.scanws_client.display.ungrab_keyboard(1, X.CurrentTime)

Who can tell me why I cannot ungrab my silly Keyboard? (this question is cookie provided 😉 )

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:05:11+00:00Added an answer on May 22, 2026 at 3:05 pm

    Did you flush the calls to the X server? Xlib is asynchronous and buffers all requests until you fill the buffer, make a call that needs a response from the server, or call XFlush (the C API interface, not sure the python binding name).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i thought i had solved this but my basic example seems to not be
Update: Solved, with code I got it working, see my answer below for the
Problem solved: Thanks guys, see my answer below. I have a website running in
edit #2: Question solved halfways. Look below As a follow-up question, does anyone know
Edit: I have solved this by myself. See my answer below I have set
SOLVED I am using delphi 2009. My program listens for usb drives being connected
SOLVED VERSION Ok so here it is. I am not even sure how to
Solved: Workable solution: sbi's answer Explanation for what really happens: Hans's answer Explanation for
SOLVED: I found the answer! I delete position:relative from CSS .over_meno li a{} ,
SOLVED: Nevermind, the links were visited, and the border definition was missing for visited

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.