I'm using readline in an application that follows the input realtime. I don't want to allow the user to press Enter, Control + J, or any other equivalent, and thus unintentionally clearing the field.
I'm actually forwarding the keys myself, so I can catch and prevent certain key inputs, but I don't think this is the way to go because reverse search (Control - R) must also be handled.
I've looked over the gnu docs, but haven't found anything useful.
My code is similar to this https://github.com/ulfalizer/readline-and-ncurses
You can inhibit this keys configuring key bindings in the initialization file of libreadline :
in ~/.inputrc to configure for current user
in /etc/inputrc to configure for all users.
To inhibit Enter and Control+J, you could add to the initialization file :
RETURN:
C-J:
If you prefer you can do this programmatically using rl_unbind_key, adding to your code :
rl_unbind_key('\r'); // unbind Enter
rl_unbind_key('\n'); // unbind Control+J
Related
I'm trying to remap my the tag display feature thats traditionally mapped to modkey, "Control", "#" .. i + 9. I have removed any other instance of {modkey, "Tab"} mappings in my rc.lua, and attempted to replace the word Control with the word Tab. However, despite the rc compiling it the command doesn't run. I have no idea why this might be hopefully one of you more experienced users will be able to see my issue.
awful.key({ modkey, "Tab" }, "#" .. i + 9,
function ()
local screen = awful.screen.focused()
local tag = screen.tags[i]
if tag then
awful.tag.viewtoggle(tag)
end
end,
{description = "toggle tag #" .. i, group = "tag}),
As Uli says in the comment, what can and cannot be a modified is a constraint coming from Xorg. It cannot be Tab.
But. With awful.keygrabber, you can create a keybinding on modkey+Tab, then from that callback, start the keygrabber and intercept the number keys from there. When the keygrabber detect Tab is released, then stop it. There is multiple built-in methods and property to make this rather easy.
See https://awesomewm.org/apidoc/core_components/awful.keygrabber.html for more details.
Just take the Alt+Tab example (link above) and modify it to fit your use case.
I want to disable certain keys while creating image in yocto. I know in users pace we can achieve this with xmodmap utility but I want to achieve this kernel itself.
I checked drivers/try/vt/defkeymap.map file and modified as per my requirement but loadkeys not able to generate defkeymap.c file. It throws this error:
/bin/sh: 1: loadkeys: not found.
Am I going in the right direction? Or is there any other option to change default keycode map?
The raw keyboard data is scan codes that the keyboard driver converts into key codes cf https://unix.stackexchange.com/questions/319787/how-does-the-linux-kernel-handle-keyboards-inputs-outputs. A way to generate a custom keyoard layout for console is in https://wiki.archlinux.org/index.php/Linux_console/Keyboard_configuration#Creating_a_custom_keymap, so you do not edit a driver file, loadkeys requires changes in specific directory / file :
As a side note, it is worth noting that such a personal keymap is
useful also to redefine the behaviour of keys already treated by the
default keymap: when loaded with loadkeys, the directives in the
default keymap will be replaced when they conflict with the new
directives and conserved otherwise. This way, only changes to the
keymap must be specified in the personal keymap.
source : https://wiki.archlinux.org/index.php/Linux_console/Keyboard_configuration#Creating_a_custom_keymap
If you want to do this on kernel module level you have to rewrite or patch the entire keyboard module.
In https://unix.stackexchange.com/questions/319787/how-does-the-linux-kernel-handle-keyboards-inputs-outputs is many essential information ( links to source code, ... ) for all levels, including solving this issue on kernel module level ( writing / patching kernel module )
Sublime's key bindings accept arguments, where can I find the list of arguments I can pass for user defined key bindings?
Documentation doesn't make it clear, google is not helping, I can't find source of this dictionary, where is it all being defined? How can I review what I can use or not?
The arguments that a command takes depend on the command itself, which is true not only for default commands that ship with Sublime but also any commands added by plugins or third party packages.
The unofficial documentation has a list of commands internal to Sublime, including what they do and what arguments they take which can be of help here. For example, given this text:
new_window
Opens a new window.
The command new_window takes no arguments. On the other hand:
expand_selection
Extends the selection up to predefined limits.
to [Enum]: Values: bol, hardbol, eol, hardeol, bof, eof, brackets, line, tag, scope, indentation.
The expand_selection command takes an argument named to, and also has a list of predefined values that it can take, e.g. "to": "bol" to expand the selection to the beginning of the line.
To my knowledge there's no official list of internal commands with the exception that they're used in the default key bindings (which appear in the left hand pane of the key bindings window when you open it).
Third party packages that define commands sometimes outline them in their README file, but many also choose to go the same route as Sublime and just document them in the key bindings files.
It's also possible for commands to appear in other places (e.g. in menus and in the command palette), which is another place to look. You can use the internal View Package File command to view sublime-command and sublime-menu files to see what they're doing as well, if you're curious.
Lastly, if you open the Sublime console and enter the command sublime.log_commands(True), Sublime will log commands as they execute, telling you what they are and what arguments they took. Note however that there is currently an issue in more recent builds where commands from the command palette are not always logged.
I am trying to find a way to paste a predefined string upon entering a specific keyboard sequence, on any app.
For example if I have to paste an url or a password into a field, I can have said password in a hidden script and when I press, say, [ctrl] + [5], it would write "example123" on the text field where my cursor is.
Ideally without copying to the clipboard (I'd prefer keeping what I have on my clipboard and also avoiding to paste a password or such by mistake elsewhere).
I have tried every solution I've found so far that include xclip, xdotool and xvkdb. All of them either do not work or are really inconsistent: They only paste the string sometimes, and when they do, it's usually only part of the string ("ample123" instead of "example123").
I thought of using compose key, which I heavily use anyway to write in french on an us keyboard, but it seems it only supports 1 character sequences, as nothing is printed when I modify my .XCompose to include custom output sequences of len > 1.
I am using Ubuntu 18.04 with Gnome as a DE. Ideally something that also works when logging back (like compose keys).
You need to walk the Document Object Model for either Gnome or your web-page. My concern is that with a desktop script you wont be able to access the web page because you will need to be able to establish a target to send string to. I see in your question that you tried using using "x{tool-name}" to grab the text field element. Delivering the sting really isn't the problem. The problem is getting the GUI element of text box pragmatically. The easiest way to get access to this in a user loaded web-page is with WebExtensions API which is how to make extensions for most modern browsers. Otherwise, if you can get away with only having access to Gnome's GUI I would try LDTP, it's a library used for testing, but it looks like it can be used for automation too.
For keyboard shortcuts:
It really shouldn't matter what the script is doing to how you want to activate it. I would just go to Gnome/Settings/Keyboard and set the path to where I saved the script to be the Command. If you go the WebExtension route, you will want to build the shortcut into your extension.
I recently understood that if I write characters inside /dev/tty it will simulate key presses with a keyboard.
I was wondering if I can simulate holding a key or a key combination.
What I'm looking for is to simulate the Alt + Tab to switch between open applications.
I'm not looking for alternatives. I am practising to learn how can I simulate a physical key press on a keyboard.
Is it possible to simulate key combinations (like Alt + Tab)?
Also, how can I press the Enter key?
It seems it's not '\n' or '\r' or "\r\n" or "\n\r".
The reason I'm looking for the Enter key is that I want do a "sudo" command in the terminal and when it prompts for a password, I use the /dev/tty to answer that, but it seems standard input or standard output (using "-S" option with sudo) don't work.
Is there anything I'm doing wrong?
Are there some libraries I should be looking for (like Expect)? Or is what I'm trying to do impossible?
I am using C++. All I want to do is to try to simulate a physical key press on my keyboard. The OS is Ubuntu 13.04 (Raring Ringtail). (Just as a practise)
But I have two goals:
To create a program which switches between applications using Alt + Tab.
interact with a Linux terminal.
I've found two solutions:
Write characters/codeASCII s of the corresponding keys to /dev/tty
Write characters/codeASCII s of the corresponding keys to standard output and/or standard input
But none of them worked. Is what I'm doing correct or not?
X does not read keystrokes from /dev/tty. If you want to simulate keystrokes in X, you’ll need to send them another way. If you’re writing a shell script, xdotool is your friend; if you’re writing C, though, you’ll probably want to use libxdo, the library underlying xdotool. If you’re looking for something a bit more low-level, you might be interested in the XCB Test API, on which both xdotool and libxdo rely.
Unless you can provide more information about your experience with sudo, I don’t think anybody will be able to answer your second question. sudo -S is definitely the intended mechanism for programmatically providing a password to sudo.