Allow hotkey that presses a disabled key - keyboard

My keyboard key/letter f is ruined and continuously presses the letter. I am using AutoHotKey to successully disable the letter, but I need an alternative hotkey to press the key. I have chosen to use CTRL+j as the hotkey to press the letter f. I tried this script but it does not seem to press the key:
f::return
^j::
Send f
return
I also tried this but it also does not work:
f::return
^j::
Send {f down}
return
How can I get the script to press f using the hotkey CTRL+j, while disabling the key f?

The $ modifier is going to solve this problem.
That modifier makes it so that your f::return hotkey wont affect keys that are sent from AHK.
So here's your finished script:
$f::return
^j::SendInput, f
Also switched over to SendInput due to it being the recommended faster and more reliable send mode.

I used the ASCII code for the letters in both uppercase and lowercase, and it also worked:
; disable the key 'f':
f::return
; press CTRL+j to press f:
^j::
Send {Asc 102}
return
; press CTRL+Shift+j to press F:
^+j::
Send {Asc 70}
return

Related

Disabling ALT menu bar activation with AutoHotKey not working on Windows 8

I've tried using ~LAlt Up:: return in my AutoHotKey script.
But to no avail the menu bar still gains focus when I lift the key up.
Why does this trick work on other systems but not mine?
Or am I doing something wrong?
Try this:
LAlt up::
If (A_PriorKey = "LAlt") ; If LAlt was pressed alone
return ; do nothing
return
; In this case its necessary to define a custom combination by using "LAlt &" or "<!"
; to avoid that LAlt loses its original function as a modifier key:
<!F4:: Send {Alt Down}{F4}{Alt Up} ; <! means LAlt
EDIT:
This works in AHK v1.1.28+ without disabling Alt + click or wheel:
~LAlt::Send {Blind}{vkE8}

vim replace multiple lines by a variable (in register)

I am using Vim and I have ${HOME} saved on a register, which is the fastest way of replacing those ../../.. by ${HOME} ?
LDFLAG = -L../../../libs
-L../../../libs
result
LDFLAG = -L${HOME}/libs
-L${HOME}/libs
If you have ${HOME} in, let sey "u, then press ctrl+v, selected ../../../ , then press s, then ctrl+R (a " should appear) and the letter of your register (u in our example).
Assuming your cursor is on the first . of ../../../ and your text is stored in register a…
With visual-block selection
Press <C-v> to enter visual-block mode,
extend the selection horizontally to the last / of ../../../,
extend the selection vertically,
press "ap to put from register a.
With a repetition
Press v to enter visual mode,
extend the selection horizontally to the last / of ../../../,
press "ap to put from register a,
move the cursor to the next ../../../,
press . to repeat.
With a substitution
Do :,+s#\.\./\{3}#<C-r>e<CR>
I don't know what "I have ${HOME} saved on a register" means but the simplest solution would be
:%s#\M../../..#${HOME}#
It's replacing all of the ../../.. with ${HOME}, or if you really using a register (say #a), then you can use \=#a instead of ${HOME} to replace the match with the contents of register a.
Explanation
:: Open command prompt
%: On the whole buffer...
s: ...replace (substitute) the match...
\M: ...of a non-magic pattern (e.g. a literal string)
#: Used sharp instead of mostly used slash (/) as separator, because the pattern contains slash

How to move behind autopaired char in insert mode in vim

I am using auto-pair in Vim (https://github.com/jiangmiao/auto-pairs). I am typing code:
= link_to 'Link name', some_path(#var|)
And the cursor in edit mode is at | position. Then I want to continue typing more params.
What is the fastest way to move cursor behind the auto-paired )?
I know I can press Ctr-O Shift-A but 4 key strokes to move cursor one column to the left is over-kill.
You could use the right/left arrow keys, but the way the plugin provides a better way of doing it. If your cursor is right next to the closing auto-paired character, you just need to type that character. For instance, if your cursor is in a position like this:
def some_func(args|)
You can just press ) to go to the right of the auto paired character. Same goes for any other closing characters that auto-pairs is compatible with.

Is there a typeahead buffer for key presses in Linux terminal?

Does Linux buffer keys typed in terminal so that you can read them later one key at a time?
I am asking because I want to catch ESC and arrow key presses and can't find a way to reliably read the codes. I put terminal in non-canonical mode and want program to block if there is no input, but if there is, I want to fetch only one key press for processing.
Update 2: Arrow keys is just an example. I need to identify key presses even for the keys with unknown escape sequences for my program.
There are two conflicting cases:
read(1) returns one character. For both function keys and ESC key this character will be 0x1b. To check if it was an arrow key, you need to read(1), which will block if only single ESC is pressed.
Solution: blocked read(1), non-blocked read(1)
Problem: if second read didn't match any function key, it may mean that it was buffered ESC followed by some sequence, or an unknown function key. How to detect unknown function key press?
read(4) returns at most 4 characters, but if you press ESC four times to let it buffer, you'll get a string of four 0x1b. The same problem to find out if there is an unknown function key press as above.
Can anybody explain how to deal with these problems in Linux terminal, or at least post a proof that Linux just doesn't have input buffer for keys?
You should read up on VT100 escape sequences.
You've discovered that the character code for the escape button (which is sent as a real character, but tends to be used almost exclusively for signalling the beginning of an escape sequence) is 0x1b.
To move the cursor UP: <ESC>[{COUNT}A
To move the cursor DOWN: <ESC>[{COUNT}B
To move the cursor RIGHT: <ESC>[{COUNT}C
To move the cursor LEFT: <ESC>[{COUNT}D
You can test these yourself by typing them into the terminal. Just type the keys one after another. My terminal does not recognize the count argument, but will work successfully if I type <ESC>[X (for X in A,B,C,D).
If your terminal isn't in VT100 mode, look up the escape sequences for whichever mode it's in. You might realize that depending too much on terminal specific escape codes restricts your program to one specific terminal type.

g++ : How can I get keystate on linux

I Want to get keystate for some key like shift. If I press "a" with shift to write "A" then by g++ program on linux how can I ensure that shift is also pressed while I press key "a".
Thanks in advance.
See the answer for this question: What is Equivalent to getch() & getche() in Linux?
It will give you the correct keycodes, i.e. 'a' if you press 'a' with shift depressed, 'A' if you press it with shift pressed, etc. Getting the state of the shift key alone is a different matter though, I'm not sure if there's an easy way to do that.

Resources