0

Disclaimer:

I am a bit of a Linux noob :(

Problem:

I have an interesting problem that I could use some help with. Essentially, I want to overwrite the default actions for the "Print Screen" button in Linux. My reasons for doing so are that I have a homemade graphics card running attached to the computer and I'm trying to make a utility where I can capture what it is outputting to a separate monitor and send it back to the "host" computer. For purposes here, I only want to know: How can I execute a script upon pressing the Print Screen button? Note that I cannot install xbindkeys or any other software. Ideally I would like to be able to run a script to enable this behavior.

Current work-around:

Currently, I have a .bashrc script:

    #!/bin/bash
    export PATH=/home/username/bin:$PATH

In the /home/username/bin folder I have a script "gnome-screenshot" that, for now, just performs some arbitrary task (it actually does this: "cat /usr/share/icons// > /dev/dsp" -- try it! It's fun!).

I am working on school computers, so I first CTRL-ALT-F5 to open a terminal login, login, then source .bashrc. I then startx -- :1 to start a new X session. Now, if I hit the PrintScreen button, it uses my gnome-screenshot, not the default screencapture program.

Is there anyway to do this without all of the restarting X? In short, is there a way to source my .bashrc script, or otherwise modify my PATH variable, before or while I login?

Another Approach:

I also tried, briefly, to xmodmap and the keycode to execute a script, but couldn't figure out how to tie them together. I know the keycode (111) but can't figure out how to run a script on press. I believe it might be possible to make a sort of binding using this but can't figure out how.

Help!

I'd really appreciate some help or comments!

(Edit): Added Details About Distribution:

cat /etc/redhat-release tells me:

Red Hat Enterprise Linux Client release 5.8 (Tikanga)

user1028435
  • 309
  • 3
  • 10

1 Answers1

3

xmodmap is not the tool you want; it cannot bind keys to programs, it binds physical keycodes to logical keysyms. XGrabKey(3) is what you're looking for.

Reading your shell dotfiles while starting the X session depends on the exact OS and desktop environment you're using (including version; there are 4 or 5 different ways you might need to use even considering only different Ubuntu versions with their stock desktops).

geekosaur
  • 59,309
  • 11
  • 123
  • 114
  • Great comment thank you! I would upvote but I don't have 15 reputation yet :( – user1028435 Apr 11 '12 at 01:42
  • cat /proc/version reveals: Linux version 2.6.18-308.e15 (Red Hat 4.1.2-50) Any idea about establishing that PATH variable? – user1028435 Apr 11 '12 at 01:42
  • That's insufficient; `/etc/debian_version` might be more helpful if it's a Debian derivative, `/etc/redhat-release` if it's (even distantly) derived from Red Hat Linux. And even so it's also a question of which desktop (KDE? Gnome? LXDE? other?) and version thereof. – geekosaur Apr 11 '12 at 01:48
  • Ahhhh thank you: Red Hat Enterprise Linux Client release 5.8 (Tikanga) – user1028435 Apr 11 '12 at 01:50
  • Ok, I'll have to ask others to respond beyond this because I'm more familiar with Debian, Ubuntu, and SuSE so don't know the peculiarities of that platform well. – geekosaur Apr 11 '12 at 01:53
  • Will do, thanks for your replies! – user1028435 Apr 11 '12 at 01:54