I have created a script to add/remove (toggle) a specific IME. Now, after that IME is added, I want to switch to it, just as if I clicked the language name at the bottom right of the screen, and then clicked that IME on the pop-up list.
I have searched Google for this, but I could not find a suitable command. The top result was Set-WinDefaultInputMethodOverride, but I was not talking about changing the default IME or the precedence; I just want to automate the manual changing as described in the previous paragraph. Is that NOT possible with PowerShell?
You can shift the IME on or off with ALT + SHIFT in Windows and cycle through the languages. The easiest way to do this is with SendKeys.
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait('%+')
This will load the correct assembly and send the ALT+Shift keystroke. A list of special characters for SendKeys can be found here. On my system this changes the language from English to Japanese, a second [System.Windows.Forms.SendKeys]::SendWait('%+') will then cycle to Scottish Gaelic. Sending a third keystroke cycles back to English.
If the language has multiple inputs like Japanese Hiragana, half width Katakana, full width Katakana, etc... you can use ALT+~ to cycle those as well. Tilde must be escaped. [System.Windows.Forms.SendKeys]::SendWait('%{~}')
Note that the application you are attempting to enter text into has to support this though. For example Powershell itself will let me switch to Japanese but will not let me switch to Hiragana, only the standard ascii chars.
I'm not sure what your ultimate goal is but this is one way to shift through your installed languages via hotkeys.
Related
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.
I have an Autohotkey function that lets me switch between tabs with "Control + left/right" as well as closing tabs (Ctrl-down) and going into the search bar (Ctrl-up). It helps me save clicks and use the mouse less.
However, I use the Canadian Multilingual Standard keyboard to type accents (éèçà) in French for some of my classes and this keyboard DISABLES the right control key (the one right beside my keyboard buttons) which is the most convenient to use with my right hand only.
Here is a source documenting this: http://archives.miloush.net/michkap/archive/2013/04/08/10409187.html
Is there any way I can override this? I very rarely use the letter œ for because I can just use ALT + 0156 instead.
Here is the very simple code for my hotkey!
^Left::SendInput, ^{PGUP}
^Right::SendInput, ^{PGDN}
^Up::SendInput, !d
^Down::SendInput, ^w
Using SciTE4AutoHotkey tool, on my UK hardware keyboard right ctrl is detected as expected (RControl)
When I switch to French (Canada) Canadian Multilingual keyboard,
the right ctrl key is not found, also Virtual Key is different: DF
(SC means scan code and VK means virtual key)
so if you remap, it should solve the problem
~SC11D::RControl
After remapping: not found is replaced by RControl with each keypress.
Even if above remapping does not work for your case, it is a matter of finding which key corresponds to relevant scan code and then you can remap it.
Double click on your ahk script on the taskbar, and then
View > Key history and script info (Ctrl + K) by pressing key and refresh(F5) you can see respective keyboard scan codes.
I know about the Trim Trailing Whitespace command in the pallette, and I know I can run this on save.
Is there a way to trim trailing whitespace on ALL files in a workspace (either with some command combo, or a way to run "save" on every file)
I have seen other answers on how to trim trailing whitespaces using Unix tools, but I would rather use the built in tool from VSCode specifically. (I would accept an answer that shows how to do this in another GUI text editor like Sublime Text also).
I would prefer not to have answers that use Terminal or other Regex matching--I would prefer to use the exact algorithm that is used by GUI tools already, since I trust that they will do the thing I expect. I will be running this on potentially thousands of files, so mistakes could easily go through even after audit.
I am basically trying not to open every file and ⌘+S it manually.
I am on macOS if that changes anything (but I doubt it matters)
This can be done using the search-and-replace function (keyboard shortcuts given below are for Linux, likely similar to what exists on a Mac):
Ctrl-Shift-H (open the search-and-replace side panel)
Type +$ in the Search field (that is a space, a plus and a dollar, meaning one or more spaces anchored at the end of the line)
Click the .* regular expression button next to the Search field
Leave the Replace field empty
Press Ctrl-Alt-Enter (or press the Replace All button next to the Replace field)
Click Replace (or Alt-R) in the confirmation pop up which also tells you the number of occurrences and files that will be touched
Be careful, as a wrong search or replace argument can mess up many files all at once!
I'm trying to make filling some web-forms easier. Each form might include 100 times that tab would have to be pressed after typing a letter to be able to input the next letter to it's corresponding slot. I tried some examples, but ran in to problems when changing Windows language settings to Russian. Most of the time I will be inputting Russian letters, and if not, then just normal latin letters.
I tried following basic examples which worked for either one letter at a time or all (latin) letters at once.
#UseHook On
w::send ш{Tab}
Which outputs
ш(and one single TAB taking me to the next input)
So for some reason the characters are not correctly output from AHK.
This other example I found here and it works fine for any latin letter after a small modification:
https://autohotkey.com/board/topic/67948-detect-any-letter-key-press/
Loop 26
Hotkey, % Chr(A_Index+96),LatinLabel ;loop creating hotkeys for a-z
Return
LatinLabel:
Func(A_ThisHotkey)
Return
Func(var) {
#UseHook On
Send %var%{TAB}
}
I read that listening for all keypresses or actions would not be ideal, since this would also record mouse clicks and even movement.
So are there other alternatives googling didn't reveal to me?
Are you having problems with sending Unicode characters?
For the euro symbol I use either of:
SendInput {U+20AC}
PostMessage, 0x102, 8364, 1, Edit1, A ;WM_CHAR
The problem of ш becoming ш is due to the script file having been saved as UTF-8 without BOM. You just need to save the file as UTF-8 with BOM. AutoHotkey (as of v1.1.30.03) interprets files without a BOM as ANSI, because the default editor is Notepad, and Notepad (prior to Windows version 1903) defaults to ANSI.
The second script registers hotkeys a-z via the expression Chr(A_Index+96), which produces latin letters. Once registered, these hotkeys will activate when you press the corresponding virtual keys even if you change the keyboard layout. However, they will still send latin letters, because A_ThisHotkey is a-z.
The solution is to use the ~ hotkey modifier instead of sending the hotkey. In that case, pressing the key has whatever effect it should normally have, then the script sends Tab.
Loop 26
Hotkey % "~" Format("vk{:02x}", A_Index+64), AzKey
return
AzKey:
Send {Tab}
return
This registers hotkeys for the virtual keys vk41 - vk5A, which correspond to A - Z on layouts which contain those characters, but also work with other layouts. However, there may be some other keys which produce "letters" or other characters you want to watch for; in that case, just register additional hotkeys as needed.
Hotkey ~vkC0, AzKey
or stack the labels
vkC0::
AzKey:
I have written a python script for my co-workers, and then created an autohotkey script to run it every time someone presses Ctrl+LShift+Y. Looks something like this:
^+y::Run helper.py
The python script is fine, but the ahk script doesn't work on all the computers. Sometimes it works fine, and sometimes you get this error:
^+y does not exist in current keyboard layout
Now, searching the web this seems to be a problem with multi-language keyboards (we're using both Hebrew and English), because different languages means a different layouts (I guess?). I also found someone explaining that to solve this you need to use scan codes instead of the usual ^ and + and so on (I'd link to it but I cannot seem to find it now).
This all vaguely makes sense to me on a theoretical level, but when I want to realize it with actual code, I don't really know what to do. To me it seems as if this topic is hardly discussed (with the few exceptions being lacking in examples or hard to understand), so I'd love an answer that would include the following:
some simple way of determining the scan code for a key. This should preferably be a pythonic solution (and just out of curiosity, I'd love to know how to do this with linux as well). This is probably the easier part (but I think is an inherent part of a complete answer).
This is the important part: examples of how you implement that scan code in an autohotkey script, including edge-cases (if there are any).
Question 1
As you want to use the key with autohotkey, it makes sense to use autohotkey detect the key in the first place. Obviously this method works only on windows where autohotkey is running.
Write a Autohotkey script with this line and run it.
#InstallKeybdHook
Press the key you want to examine.
Open the script menu by right clicking the icon of the script in the right lower corner of your screen.
Select OPEN, then from the Menu "View / Key history and script info"
There is a line for each keypress.
First column is the VK (Virtual key) code, next is the scancode.
For example for CAPSLOCK the VK is 14 and the Scancode 03a
Question 2:
#InstallKeybdHook
VK14::
msgbox, you pressed capslock!
return
OR
#InstallKeybdHook
SC03a::
msgbox, you pressed capslock!
return
both work.
Note that you can combine two keys into a hotkey by combining them with & (but not 3)
#InstallKeybdHook
RShift & SC03a::
msgbox, you pressed Rshift capslock!
return
You can modify a Scancode with + and ^
#InstallKeybdHook
^+SC02C::
msgbox, you pressed Ctrl Shift and Y(maybe)!
return
Further info about this is on the page "List of Keys, Mouse Buttons, and Joystick Controls" of the autohotkey help file that comes with the default installation.