Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When watching a movie on a laptop, it should cleverly disable its screen:

  • If no external screen is plugged, don't disable.
  • If a modifier key is used to open the movie, don't disable.
  • If an external screen is plugged and no modifier is used, disable the laptop screen.
  • When the media player exits, restore the laptop screen.

I've written the following script:

if [ "$(cat /sys/class/drm/card0-VGA-1/status)" = connected ]
  xrandr --output eDP1 --off
  vlc "$1"
  while [ "$(pidof vlc)" > 0 ]
    sleep 1
  xrandr --output eDP1 --auto --below VGA1
  vlc "$1"

eDP1 represents the laptop screen, VGA1 the external screen. The script is used by associating movie files in ~/.local/share/applications/mimeapps.list with the following desktop file:

[Desktop Entry]

Can you suggest a way to modify the script or the desktop file, or any other way to check for a modifier key - the only restriction being that a single action must be used to open the movie.

share|improve this question
up vote 2 down vote accepted

There seems to be no off-the-shelf solution. However, it is not difficult to use Xlib and Xkb directly.

Create a file getmodkey.c:

#include <X11/Xlib.h>
#include <stdio.h>
#include <X11/XKBlib.h>

int main() {
    XkbStateRec r;
    Display* d = XOpenDisplay(NULL);
    XkbGetState(d, XkbUseCoreKbd, &r);
    printf("mod: 0x%x\n", r.mods);
    return !( r.mods & 1 );

and compile it with -lX11, for example

make LDLIBS="-lX11" getmodkey

The exit status code of the program would be 0 if the Shift-key was pressed, 1 otherwise. To test for a different modifier, adjust the (r.mods & keymask) condition (the mask for Shift is 1).

Then, this program should be easy to integrate,

if getmodkey; then 
  echo "shift!"
  echo "no shift"
share|improve this answer
I'll look at it later today, but I wanted to thank you in the meantime. – pouzzler Sep 26 '12 at 8:21
Thank you, just perfect. – pouzzler Sep 26 '12 at 16:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.