Detect Keypress in background Linux in c/bash - linux

I want to detect a key combination like alt+g in an application that runs as a background process (other keypresses/combinations should be executed normally) ,
if the combination is pressed i want to block all keypresses and send them via serial to another linux pc instead of executing them. I cannot find a solution for detecting the key combination and recording the keys within a background process.
I'd prefer to use a bash script, but c is ok aswell.
I just cant find a starting point. Any directions or help are appreciated.

Using Xlib I managed to fetch the keyboard Input http://www.x.org/releases/X11R7.7/doc/libX11/libX11/libX11.html

Doesn't the application screen do what you want? Allows you to detach & reattach to sessions on another PC over network (which could be connected over a serial line)?
10 Screen command examples and
How to use Linux Screen

Related

How to re-size screen size over serial terminal

I'm developing serial terminal sw and trying to resolve asynchronous screen size.
Below is in detail
There are modem_[a,b] and modem_a's uart1, _b's uart0 are connected(Main console port of both is uart0).
serial_app on modem_a attempts to access to modem_b via serial line.
serial_app uses termios library
And it's possible to serial-access to modem_b then it provides terminal service like putty.
But I change console window size then it starts asynchronous display.
However, I execute resize command then it becomes fixed.
So I checked SIGWINCH and it was triggered on modem_a but not on modem_b. And I've looked for how to pass SIGWINCH through serial terminal or cause SIGWINCH over modem_b controlling terminal settings like ioctl_tty(), escape sequence(\e[8;$Height;$Width, ...) , and so on...
Eventually I failed..
I'd like to maintain synchronous display whenever I change window size.
So you guys, Do you have a solution? or anything else?
I found out why I was unable to automatically synchronize window size and display on serial terminal. It's just there is not a mechanism on serial terminal.
So, we should manually synchronize window by resize command on that.
Reference:
source : http://lists.busybox.net/pipermail/busybox/2009-May/069226.html
source : https://wiki.archlinux.org/index.php/Working_with_the_serial_console

How can I create a button (or hotkey) that will automatically connect my bluetooth headset?

I have a bluetooth headset that I would like to be able to quickly switch between connection from my laptop(running windows 8) to my phone. I downloaded autohotkey to help me make a hotkey that would connect to my bluetooth headset, but I was only able to make a hotkey that would open the bluetooth control panel for my specific headset, which is not what I was trying to accomplish. What I am trying to accomplish is a hotkey that would immediately connect my headset when typed.
The code I used in autohotkey, to open the bluetooth control panel(by clicking Ctrl+Alt+B) is:
^!b:: run "C:\Program Files\WIDCOMM\Bluetooth Software\BTWUIExt.exe" /deviceAddr=445ef3aa5294
this code won't work for you as the numbers and letters on the end are a uniqe idendifier for my specific headset. You can find your unique id by opening bluetooth in the control panel and right clicking your headset, selecting properties, clicking the bluetooth tab (remove the dots and colons).
This worked to connect the first bluetooth device in the list (Windows 10)
#SingleInstance,force
;https://autohotkey.com/board/topic/83571-autohotkey-connect-to-bluetooth/
^F1::
Run, bthprops.cpl
Sleep, 2000
Send, {tab}{tab}{enter}{tab}{enter}
Sleep, 200
Send,!{Tab}
return
There is very little information to give exact solution. But from given information I can say:
You can automate GUI with AutoHotkey so that script will go to the
place where unique id is located. In fact, AutoHotkey allows any
GUI automation (conventional or non conventional GUI).
If the unique id is there as a text and you can copy it, then it
also can be automated by several ways. If unique id cant be coped
and is as image, then it is slightly complicated and you need to use some OCR
techniques. In that case you need to make screenshot of that region
and use some OCR script getting text out of it. Or with AutoHotkey pass image to OCR software and get text from it.
After you have text, you can manipulate it the way you like. Most powerfull solution
is Regular Expressions which are supported by AutoHotkey.
When unique id is ready to use, you can use it in Run
command this way:
^!b:: run "C:\Program Files\WIDCOMM\Bluetooth Software\BTWUIExt.exe" %MyUnicIDVariable%
Turns out that the code I have works on its own. If I just wait for about 10 seconds after typing out the hotkey, the headphones connect, and the control panel that opened automatically closes. Quite convenient actually as I didn't expect it to connect or to auto-close the window.
Thanks for the effort anyway!
Try to install [Broadcom Bluetooth 4.0 Driver for Windows 8.1 ] LINK=>> 1 !
At least works fine on my HP-EliteBook-8570p with stereo "BlueDio 99B" headset. After switching the headset ON the Windows connect the device automatically, and switch Audio-Stream into new-attached device. Optimal!
PS - Unfortunately it is still the Problem with Windows 8.1 + Skype( MIC-Problem) :( Windows 8 is the first OS, than not support Skype at all! ;)

alt-tab like functionality when using terminal?

When working in GUI we do alt-tab (or cmd-tab in mac) to switch between multiple programs, for example I am writing a text file in a text editor and then I do alt-tab to switch to already running browser to google up something then I alt-tab again to come back to keep editing.
How do you perform such "switch between" programs in command line interface - for example working with a ssh command line shell?
EDIT: I forgot to mention it, I am using ssh to connect to my university's server, and they don't have screen & tmux installed, and my account have no right to install any new apps... Is there any built-in functionality to perform this task, or any work around? For exmaple can I "minimize" running proggram and come back to regular shell interface, do some work, then display the "minimized" process again?
Another workaround: use the shell's job control, eg if you're editing a file, CTRL-z pauses the editor and brings you back to the shell, where you can compile, see manpages, browse the web or whatever -- and of course you can background the browser or anything else.
Screen command offers the ability to detach a long running process (or program, or shell-script) from a session and then attach it back at a later time.
As a crude workaround, run multiple terminal windows on your computer, and alt-tab between them.
Incidentally, at the Linux console, you can switch virtual terminals with ctrl+alt+F for at least F1 through F6, commonly F8 or more (depends on how the distro sets them up). Not your case, I know, but in case future visitors should benefit.
If you are comfortable in Emacs, it allows you to run multiple independent ansi-term buffers.
You can also use "GNU screen" to emulate multiple terminals in one terminal.

Debian Start Qt GUI application with no desktop

I have Debian 2.6 running on a SBC that I plan on using in an embedded setup. What I need to do is configure it so that linux will start up and run just my Qt GUI application. Do I need a window manager to do this or can I just do it with X11. Also because it is going to be for an embedded system I do not want to load any desktop manager. Any info on how this can be done would be great!
Yes you can do this without a window manager.
first: You need to boot into a non X session, init level 1 or 3.
second: You need to start the X server, in a basic mode by just calling X or xinit.
third: Start your app. You may need to take a little more control over where your app is positioned on the screen and its dimensions in your code, as you will not have a window manager to help with this.
alternatively: you can launch one of the more basic window managers to see how they play with your system. Motif Window Manager (mwm) and Tab Window Manager (twm)
Note: While working without a window manager, you may get into a state where you cannot do some very basic operations (ex: close a window, move a window, resize a window). You may find that you cannot survive without at least some of the more basic window management functions. Until you close the loop on this, remember, Ctrl + Alt + Backspace will kill the XServer.
If you want to start your app just with X11, you need do:
copy file /etc/X11/xinit/xinitrc to ~/.xinitrc
write all you want to run to it
run command startx
It worked for me and I hope it will help you

system wide keyboard hook on X under linux

What would be the best approach to install a keyboard hook on Linux (X-windows) in order to trigger some application when some key-combo is pressed?? Is there a way to do this regardless of which window manager is running? The idea is to have an application being called ( or brought to foreground ) when some key is pressed in a way similar that Google Desktop does to Ctrl-Ctrl.
XGrabKey on the root window is how xbindkey does it. Be careful about having some alternative method of killing the grab though, it's very annoying to have to go somewhere to ssh into your own box just to kill that process... And that's why, if it was me, xbindkeys+"echo 'moo' > /tmp/moo-fifo" would be the way to do it. That way, you could also control it in any number of other ways you haven't thought of yet.

Resources