How exactly does one find out the status of the lock keys on Linux (2.6.x), using C?
(I have a crappy keyboard without LED's for this stuff, and I need to write an X11 app to do this)
If such an app exists (and is DE agnostic - I run e16), I'd also like to hear it as well.
You can use the led addon to gkrellm. If you want to develop your own app, you can always look a the gkrellm-led sources (Ubuntu). And, of course, you can always go with xkbvleds (source).
Anyway, you can always use XkbGetIndicatorState to read the indicators from your keyboard.
Related
I was wondering if it was possible to change the key repetition behaviour(on Linux) in such a way that instead of it starting to spam one key as input it goes through all the pressed keys instead (perhaps system("something")?) So instead of when pressing two keys the keys going "wssssssssss", it should go like "wswswswswswsws" instead.
Yes, if you implement an Input Event daemon that grabs (for exclusive access) that keyboard input event device, and produces suitable autorepeat events for keys being pressed long enough, emitting press, autorepeat, and release events back to the system via the uinput device.
I am not aware of anything that already does that, but I estimate it would be less than 500 lines of code in C to implement such a daemon. Such a daemon would need superuser privileges ("run as root"), though.
For command-line game or utility that needs to detect multiple keypresses, using ncurses is way simpler. For graphical applications, the widget toolkit (GTK+, Qt, SDL2, Tcl/Tk, FLTK, and so on) do support multiple keypress detection natively.
If you wanted to write C code without ncurses, you can use termios to control the terminal interface, turn off echoing and line buffering, and achieve the same thing as ncurses – but ncurses also provides nice terminal output functions, and works on basically all terminals and emulators, too.
I have 2 questions about emulate and libnfc.
I saw on PN53x that i can't emulate iso14443b with pn53x , why is that? how can i emulate it on another way ?
when i tried to emulate tag type 4 with the exmample that on site with 2 reader of acr122u.
when i put those 2 reader Close (1 for emulate 1 for read) i get on this line ba 00 every second.
why is that? is that the reader looking for tag?
I don't find the documentation of this command, what should i answer to this so i can start the conversation between the emulate and the reader?
You can't emulate 14443B with PN532. It is impossible on the firmware level. But you can use board, based on TI RF430CL330 or RF430CL331 for your application. I am not sure if such boards are sold somewhere, but there is no difficulty to develop custom one, there is RF430CL330 Arduino library on github.
Not familiar with libnfc, but that 0xba seems to be sent from application level. If both of your cards runs libnfc-based software you could do search over the libnfc sources to see where it comes from.
I have to write a linux kernel module, which change character printed on the screen after pressing a key (let's say - I want 'a' to be printed when I press 'b' on keyboard). What is the best way to do it? I'he thought that good idea is to create module for keyboard. I did some research, i saw few keyloggers (as kernel modules) but all of them where able only to listen what key was pressed, and any change of scancode was imposible (which is pretty obvious in keyloggers). I read 3rd chapter from Linux Device Drivers, and i started to read 6th, but they are talking only about virtual devices, when i want to connect my module with the real device. I saw also this https://stackoverflow.com/questions/33836541/linux-kernel-how-to-capture-a-key-press-and-replace-it-with-another-key, but it wasn't working. My teacher said there is much eaysier way than using interrupts, but I have no idea how to do it (neither using interrupts and any other way).
What should I do? just read next chapters of LDD? Or any other book? Or maybe just lie down and cry?
Here's a very simple example of keyboard driver kernel module: https://github.com/raleighlittles/Olympus-MAJ-1428-Keyboard-Linux-driver/blob/main/hid-olympus-maj1428.c
I had a keyboard that generated weird scancodes for certain non-character keys (read the file, it explains more). Instead of using those scancodes, I wrote code to remap them to the extended function keys (F13, F14, etc.). You could use the code and instead simply switch the scan codes that you want by changing the key_mapping variable.
We have an embedded SoC running BusyBox Linux (kernel 2.6.x), and we have a need to monitor or at least notice in a timely manner when the network connection goes down or comes up (catching other events would be good but not essential).
I've spent a long time googling & reading SO threads and there seems to be a ton of different answers depending on the exact task at hand on the particular OS and the phases of the moon etc.
Our specific criteria are:
We are looking from inside a C program, so C code is preferable to command line calls.
Although the interface is always there, we can't guarantee it is or has ever been up (I have seen comments on some examples that only work when the interface is up even if the link is down)
It would be nice not to have to poll, but rather to send/catch status change messages as and when they happen. I believe the kernel may already get such messages from the driver, but I'm not sure if there's anything we can hook into?
I've narrowed the likely seeming answers down to a few candidates but can't work out which is the nicest (least overhead, most reliable, least likely to break in future versions):
cat sys/class/net/eth0/operstate
cat sys/class/net/eth0/carrier (I can find no good explanation of the difference between these two)
Using ifreq or various sequences of ioctl calls to read the socket status (looks kinda messy to me) as per answers here and here (more tidy looking).
Somehow catch status change messages???
You can use inotify to keep check on the /sys/class/net/eth0/operstate. Inotify allows different events to be watched on specified file or directory e.g. CREATE, MODIFY, WRITE etc.
You can seen the working example here
I am using C in Fedora Linux to build a voice streaming application. I have audio running between two clients, but the next stage is to implement the user interface.
I am aiming to use different keyboard keys in a "push to talk" style, ie holding the "Q" key allows the user to talk to one user, "W" another and so on.
My question is, how would I go about implementing this? The transmit thread is just a while loop that reads 180 bytes from the sound card and sends it as a UDP packet. THe mist obvious issue is echoing of the key pressed, filling the screen with q's and w's, and how I can detect key down/key up in C. I am looking at ncurses but it is a big topic!
Any ideas or further reading would be greatly appreciated.
J
The first part of your question, as to how to detect keypress without using ncurses is answered excellently, using termios, by #jim mcnamara
And ncurses doesn't seem to be as scary as it sounds :-). Here is an ncurses implementation which exactly ( almost ) satisfies your requirement. But according to this post, you need to add a notimeout() call so that getch()(ncurses one) doesn't wait for next keypress.