Autohotkey to select text under cursor? - autohotkey

Is it possible to select text under cursor using Autohotkey specifically, using a mouse and a key combination. e.g. I specifically want to just do a Ctrl-click on any word in IE/FF/Foxit Reader and a webpage with first Google search result opens up.
Thank you.

Yes it is possible...
The easiest way is to set Ctrl+LButton to double click (which selects the current word under the cursor) copy the word to the clipboard and then use google with the parameters "q=" for the search term and "btnI=I'm+Feeling+Lucky" for using the "I'm Feeling Lucky" function.
It would look like this:
^LButton::
Send, {LButton 2}^c
Run, http://www.google.com/search?&q=%clipboard%&btnI=I'm+Feeling+Lucky
return
This would work in most cases without issues, the issue comes when selecting words like:
53°C
Jhon's
test%s
and others, because double clicking them only selects the first part of the text before the symbols.
So as long as you are double clicking normal words this should work fine.

Related

How to remap Tab key to two dots/period key presses

I want to map two dot/period key presses to Tab key in AutoHotkey script. I tried to map similarly as its shown for remapping semicolon key - on AutoHotkey forums, but it doesn't work. I tried following:
1. `..`::Tab
2. ..::Tab
AutoHotkey gives an error
.
I tried searching on AutoHotkey Remap docs, but couldn't figure it out. The period key is the one with the greater than mark and not the number keypad period key. See this: Dot/period key
Addition info/context in response to reply by user 0x464e:
Basically, I am trying to expand Emmet style abbreviations in devtools style sub-panel since the chrome devtools team wont implement it.
I am not a fast typist, so it's a pain to type complete property names. For example, if I want to type margin-top, (see the image), Chrome autocomplete brings up margin, margin-block margin-block-end etc.
Now, for margin-top, you need to at least type margin-t to get the autocomplete to show that property.
This is the case for many very common CSS properties like margins, paddings, etc., so autocomplete isn't great.
On the other hand, if I just type mt and have Autohotkey expand to margin-top, it's much much faster, saves me much time and keeps me sane.
Basically, I have setup some hotstring in .ahk script and they work too.
However, if I press mt followed by a Tab key press, Chrome's autocomplete takes over and hotstring fails, (try once to see the problem). Instead, currently I press spacebar, or . (period) to trigger the hotstring. It works, but the problem is it leaves a space or a dot with the expanded text. [see this].
So, that's the actual reason I wanted a double period key trigger to replace Tab.
It would be great if the hotstring trigger would work with a double period key, but doesn't leave the trigger character itself and then have send Tab so as to jump to the value input of the just expanded property.
You're not really looking for a traditional remap, which is why you didn't find it from the documentation.
Remapping is just simply remapping one key to another, but you're not trying to do that. You're trying to make some action do another action.
Anyway, what you're asking is doable, but there's loads of different ways it can be achieved with difficulties varying from simple to extremely advanced & complicated.
You'll need to specify things more clearly before this can be answered properly.
Biggest questions that pop into my head right away are at least:
Should this work everywhere, or just in text input fields?
How should the original functionality of . be preserved, if at all.
(What should happen after the initial . keypress?)
Should there be some timeout between the keypresses?
Etc, this is just what I could think of right away, but surely there's more.
Anyway, for now I can give a simple implementation with a hotstring:
:*?:..::{Tab}
So this is a hotstring with the * and ? options.
I'm guessing these would probably be pretty good options for this.
So what this does, is it presses backspace twice and sends a Tab if you type ...
This should be fine for text editors, but it leaves much to be desired (the points I listed above aren't considered since I can't know what you're looking for. This is just what a default simple hotstring can offer).
Looks to me like you don't actually want the additional mapping of .. to Tab, but instead just want to update your existing hotstrings to activate immediately (without waiting for an EndChar) when the hotstring is followed by ..
Normally, you might look to the Ending Characters option to create this functionality, but since you want multiple characters to trigger this, we need to look to other options.
I will be using the example of ::mt::margin-top for my sample implementation. Extend any changes I make to these to the rest of your hotstrings in the script you screenshotted.
Here are the changes I am making to this example:
Add your .. to the end of each of your hotstrings triggers. For example ::mt::margin-top becomes ::mt..::margin-top. However, at this present, this still requires some sort of ending character to be pressed in order to proc. Let's fix that in the next step
Add the Asterisk Modifier to the hotstring. From the docs:
* (asterisk): An ending character (e.g. Space, ., or Enter) is not required to trigger the hotstring.
Final code for ::mt::margin-top example:
:*:mt..::margin-top
And extend this * insertion and .. appendation to each of your hotstrings.
Hope this helped! Lmk if you need any more help or changes.

how do you select only the entire string in vscode?

I tried looking up this questions but they were for the entire line.
My question is for example let url = "https://robohash.org/hello.png?set=set4";
here, is there any shortcut to select only the url or basically anything enclosed between "". Is it possible?
I just found a magical shortcut :)
For expand selection we can use shift + alt + ->
I had installed a stupid plugin before!
AFAIK this is not possible without an extension. You can download Quick and Simple Text Selection, the use ctrl+k " shortcut.
If you're familiar with Vim, you can use the vim extension, and then click v i " to enter visual mode, and choose everything between double quotes
For the sake of completeness, vscode also includes a smart select option, which has the keyboard shortcuts ctrl+shift+right_arrow and ctrl+shift+left_arrow (The shortcut has been changed to alt+shift+left/right_arrow). The problem with it is it doesn't specifically select everything between double quotes, and in the case of a URL, it doesn't simply work as intended. If it's only a simple string, it would also select the double quotes in addition to the string between them
There is actually another expansion called expand_region with the ability to
expand_region and undo_expand_region. The default keybindings are ctrl+w / shift+ctrl+w .
I find this one to be more convenient.
It stops before and after " and it will work for the url-fetch scenario.
What it doesn't do is to stop at a complete line (with and without indentation) which smart select seems to do. There are probably more differences that I don't know about.
Update: You have to press multiple times to expand further. For the example line in the original post this means 3 times.
ctrl+w, ctrl+w, ctrl+w
let url = "https://robo[cursor-here]hash.org/hello.png?set=set4";
1. https://robohash.org/hello.png?set
2. https://robohash.org/hello.png?set=set4
3. "https://robohash.org/hello.png?set=set4"

Netbeans surround selection with quotes

I want to surround the selected text with quotes or parentheses when I hit the corresponding button, not to overwrite it, which is the behavior I have observed. From what I have read so far, this is how the program usually behaves, but definitely not my case. I could not find the equivalent setting under Tools > Options. I have found the macros to surround a single word, but I want the whole selection, as would be expected in other text editors and IDEs.
Version: Apache NetBeans IDE 12.2
For example - the selection:
a string consisting of multiple words
Press Shift + 2 (where " is on my keyboard layout):
"a string consisting of multiple words"
OK....
You were right when you said that you could not find anything close this shortcut. I looked through the entire list and there was none. The only thing close to it was to surround a single word in quotes. So, that means that you will have to create one shortcut to surround text selection in quotes and another with parentheses. They will be very similar, but will require two different hotkeys.
For example, I created a shortcut to surround text selection in quotes. To do so, you have to go to Tools -> Options -> Editor and click New button
In the "New Macro Dialog" enter a name (i.e. "quote-selection") and click "OK". Then, type in copy-to-clipboard "\"" paste-from-clipboard "\"" in the "Macro Code" text area. Lastly, click "Set Shortcut..." button and type in the exact sequence of key presses you want to use for your shortcut. Don't worry if you enter a shortcut already in use. It will warn you if you do. I chose to use CNTL+ALT+3 because that's not in use. When you are satisfied, just click "OK" to record your shortcut. If you make a mistake in the key presses, simply click "Clear".
Then, repeat the process for surrounding with parentheses with the macro code copy-to-clipboard "(" paste-from-clipboard ")". When you are done, click "Apply" and "OK".
I used Netbeans version 12.3, so I expect everything shown here should be very similar (if not identical) to 12.2.

autohotkey type in another window with gui

Autohotkey Example Needed
Need some help, please. I've searched and can't seem to find an example of what I need.
What I want to do is create a ahk dialog box with a button (I can do this part), and when I click on it, it will type some text into another window. Basically, I want want to offload the "shortcut" to a "mouse click". But, without mapping a shortcut.
Something like this:
When user clicks BOX1, "text" is stored. Then, when user clicks elsewhere, vBOX1 is typed into the cursor location of the window activated by that click
I hope I'm explaining this succinctly. Any help would be appreciated.
Here are two possible alternatives:
First alternative expands #scso's suggestion:
~LButton::
sleep, 200 ;give the window below the cursor some time to get activated
Send, %vBOX1%
return
Now this may seem fine but what it actually does is type the text EVERY time you click the mouse in ANY window. Let's put an additional check so if vBOX1 is empty it doesn't type anything.
~LButton::
sleep, 200 ;give the window below the cursor some time to get activated
If (vBOX1 != "")
{
Send, %vBOX1%
vBOX1 := "" ; clears the contents of vBOX1
}
return
Second alternative:
You use the mouse clicks normally and the text gets typed only when you do Control + Click.
So in order to type the text you need to click once to select the window and then control+click to do the actual typing
~^LButton::
Send, %vBOX1%
vBOX1 := "" ; clears the contents of vBOX1
return
You can expand both alternatives by adding commands for detecting the active window and then typing the text or changing the mouse click combination to something else.

AutoHotkey: How can I paste text into this particular textbox?

Using AutoHotkey, I have a very tiny script to write text:
^m::
SendInput Foo
Return
This works in most places like Notepad and chrome. However, it doesn't work for a particular program I am using. The program has a simple textbox which I can type text into. The program is called TextExpander. I am making sure the cursor is located in the textbox. For some reason, I can't get auto-hotkey to type text into it.
Any help? Tips?
You can look at ControlSetText. Use WindowSpy to check the control name. If it has one, you can use that to set the text.
Alternately, make sure you're trying SendInput/SendEvent/SendPlay.
If you have a way to reliably focus the box you're trying to enter text to, you can put your variable onto Clipboard and send paste via Ctrl+V SendInput, ^v.