ahk send alternative in bash script - bash

I want to achieve in a bash script, that when I press any key (e.g. F5) and then type any word (e.g. "hello world"), regardless of whether I positioned in the terminal, or text-editor or browser...
While I was using Windows, then I used Autohotkey for that.
How could I achieve that with bash script in Linux?

While as #Socowi mentioned, you will likely not be able to do this with bash alone, you can use AutoHotkey Linux alternatives like AutoKey for this.
For your specific question, see this guide for setting up and configuring AutoKey on Linux.
More specifically, scroll down to the section labeled "Inserting repetitive text using a hotkey" for how to configure a text-typing hotkey:
Inserting repetitive text using a hotkey
Abbreviations is only one way of inserting text using AutoKey. If you
prefer, you can also insert text using a keyboard shortcut, which
doesn't require typing an abbreviation.
To insert some text that you need to type frequently using a keyboard
shortcut, click the Set button next to Hotkey, then click Press to Set
in the newly opened window, and press the key combination you want to
use for this phrase:
Make sure you use a hotkey that's not already in use or else it may
not work / it will interfere with the already set hotkey. To try this
out, set it to something like Ctrl + F1 (which shouldn't be set by the
system at least).
Remember to click the Save button in the AutoKey toolbar after setting
the phrase hotkey, or else the changes won't have any effect. Now try
it out: focus a text editor, some text field in a web form, etc., and
press the hotkey you've set in AutoKey - the Testing AutoKey text
expansion on Linux phrase should be automatically inserted as soon as
you press the keyboard shortcut.

Related

Produce typing lag on purpose

I have to use USB barcode scanner in application running on remote desktop. This scanner is being recognised by Windows as keyboard. When I try to scan barcode however, every 3th or 4th character is being changed to another one. When I type numbers by hand, they are being correctly written. The question is: is there any way to programmatically produce "lag" on keyboard globally? I would like to create for example a half second gap between keyboard input events and a result on the screen. Some time ago I worked with Windows hooks, and I was able to change keyboard input globally, but I remember I had problems with delaying it. Is there any other way?
you can make an autohotkey script to listen to a keyboard input, wait and then press the same keyboard button.
once you have intalled AHK(autohotkey) , you can do a AHK script whit the intructions that are in the ahk documentation.
Right-Click on your desktop.
Find "New" in the menu.
Click "AutoHotkey Script" inside the "New" menu.
Give the script a new name. Note: It must end with a .ahk extension. Ex. MyScript.ahk
Find the newly created file on your desktop and Right-Click it.
Click "Edit Script".
A window should have popped up, probably Notepad. If so, SUCCESS!
i::
sleep, 500 ;
Send, i
Return
(you can change the "i" for other keyboard keys).
a function would reduce the amount of code that you use, but i don't know how to do it in a AHK script

a basic keystroke map

I downloaded AutoHotKey today and read the tutorial. What I want to do is have an F2 key do a shift-ctrl-S in one application. I cannot figure out how to do that by reading the tutorial. How can I do it?
Firstly, install autohotkey on your system.
Once installed, create a text file and save it as .ahk (rather than .txt).
Within the file, at the end, type the following code:
F2::Send +^s
Save the file then double click it to run the program.
This will change F2 to your shift-control-s in ALL applications.
To make it application-specific, when running, right click on the icon in the taskbar and choose "Windows Spy". Click into the application you want to use the F2 shortcut in and make a note of the line just below >>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
Now, change your script to this:
#IfWinActive INSERTWindowsSpyWindowTitleHERE
F2::Send +^s
#IfWinActive
Obviously making sure to change INSERTWindowsSpyWindowTitleHERE to what you got from windows spy.
Save and run your script. Autohotkey will now only make F2 do that shortcut when the window (found via Windows spy) is active. (The last #IfWinActive is used to "reset" checking for that window in code below where this is typed - useful if you're going to type more autohotkey code in the future)

emacs control D key binding overridden

Any solutions out there for dealing with google script code-editor turning "forward delete" into a "kill line" binding? I'm used to the hidden cocoa/emacs derived navigation keys. Google decided to mess with control-d.
Clarifications:
This occurs when using the code editor. (edit-view?)
I would rather stop the google behavior than cope with it.
To understand more how fluid the control-key navigation can be
(and therefore how annoying when missing), try this...
set caps-lock to be the control key
open a cocoa browser like Safari and
start a script at https://script.google.com/
switch briefly to address bar
hit ctrl+a (goes to start of line)
hit ctrl+d (characters get deleted 1 at a time)
hit escape
switch to script area and try same thing (whole lines get munched!)
If you mean while you're working on your program in that editor, press the forward-delete key. On Apple's laptops and wireless keyboard, it's fn-delete (where by “delete”, I mean the backward delete, the key that is a.k.a. “backspace”).
You could try KeyRemap4Macbook.
Today I noticed that this problem no longer exists. So when editing a script file in the macro editor, emacs shortcuts WORK as expected. I cannot tell if they simply removed a bug or override, or actually patched it to work.

Safe keyboard shortcut for activating code completion style functionality in Mac OS X browsers

I'm building some code completion style text expansion functionality for text areas and inputs in a web application. I'm trying to work out a safe keyboard shortcut for invoking the completion proposals for browsers running on Mac OS X.
I've eliminated some potential candidates:
Command + Space - activates the Spotlight search field
Control + Space - activates the context menu in Firefox
Esc - cancels any background XMLHttpRequests in Firefox
That leaves Option + Space. I'm aware that may conflict with tools like Ubiquity, but that's something we don't expect our audience to be using.
Are there any conflicts I may have missed with Option+Space? Or do you have a better idea for a keyboard shortcut, and why?
A lot of Mac OS X apps use Option + Esc to do code completion or code hints.
Some kind of tab shortcut sounds like the best and most intuitive approach - users should be used to the 'type-tab-type-tab' workflow - maybe combine it with a modifier if it only wants to be optional.
As I recall, Visual Studio and TextMate both use tab to code-complete. In Visual Studio an intellisense menu pops up as you start typing and tab acts as the selection confirmation.
In TextMate, you start typing part of a command then hit tab to activate said command's associated "bundle". The associated bundle typically generates a code snippet and fills in any dynamic parts of the snippet as you type.
Come to think of it, most command lines work this way as well, auto-completing file names and paths when tab is pressed after typing a few characters.
EDIT: You say tabs are needed for field switching in a web interface, but you may want to try intercepting the keyboard event in the textfield, and check if they're started typing a macro. If they have, auto-complete and swallow the key by returning false; if not, simply let the command bubble through.
I discussed these ideas with our design team. One of them suggested using Control + Enter, which is what we decided to go with. This causes forms that only contain a single input field to automatically submit in Firefox, but we deal with that by preventing the default action caused by the event.
I re-assigned the Spotlight command to Command + Shift + Space. This is easily done via Prefrences.App

Page down and page up in Emacs on Windows using the Windows key

I am trying to learn Emacs and trying to find best keyboard layout for me. One thing is really annoying me. I have added following lines to .emacs
(global-set-key "\C-y" 'scroll-up)
(global-set-key "\M-y" 'scroll-down)
When I hold Control and press y a few times, it will page down on every press of y.
However, when I hold the Windows key (mapped as Meta) and press y a few times it will only page up on the first press of y and all subsequent presses of y I get the ‘y’ character inserted in the buffer.
Can the page up behave like page down? I want to hold Meta and keep pressing y to scroll multiple pages up.
I am using GNU Emacs 23.0.60.1 (i386-mingw-nt5.1.2600) of 2008-05-12 on LENNART-69DE564 (patched). It is Emacs with EmacsW32 patch. Is this problem with this Emacs? Problem with Meta key?
I tried original GNU Emacs (not patched) and it works OK with Alt. But my problem is not that I want to scroll without releasing any key. I release key y and press it multiple times but don't want to have to release Meta key. Same problem is described here:
http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/f30f4b75a8b75b10
Problem is not in that I have changed key mapping. It looks like it is a bug in EmacsW32 version. Here is another description of the problem:
Unreleased Meta/Win modifier
Use C-v and M-v.
Don't change C-y, M-y default bindings.
Could this be a side affect of using the Windows key as Meta? I'm thinking this because in a non-Emacs situation if you press and hold the Windows key and another key for a short cut (Win+E for Explorer, Win+R for Run dialog, etc.) the desired action only triggers once, not multiple times if you keep holding it down.
I'd try reassigning Meta to Alt and see if the problem persists. If it doesn't, then I'm not sure what other option you have, since likely it's the OS only sending the Windows key press once to the app in focus.
You should use the patched EmacsW32 version, if you want the Windows key as Meta.
From the site about the patches:
"Changes that makes it possible to use the window keyboard keys as META in Emacs. Without this patch key sequences like E will always do what they by default does in windows, ie in this case open up Windows Explorer. (This patched is not used by default, you have to turn it on.)"

Resources