I want to create a hotkey Ctrl + ( that adds brackets to a phrase. I.e select x-1 to get (x-1). How to program this function?
I write a lot of phrases such as: x+1/(x-1)^2 so it would be helpful to have a hotkey to add brackets.
^(::
SendInput, ^c
Sleep 10
Clipboard = (%Clipboard%)
SendInput, ^v
return
This implies that you are actually pressing CTRL+SHIFT+9 (since you don't have a ( key).
I did a quick test and it will add round brackets to anything you highlight. I would recommend tweaking the trigger key since CTRL+SHIFT+9 isn't that easy to hit, but otherwise seems to work without issues.
If you want to save the clipboard, then you'll have to do this:
^(::
SavedClipboard := ClipboardAll
SendInput, ^c
Sleep 10
Clipboard = (%Clipboard%)
SendInput, ^v
Clipboard := SavedClipboard
SavedClipboard =
return
Related
I started a little script using CAPSLock key for navigation (This is only part of the code):
SetCapsLockState, AlwaysOff
CapsLock & i::
if getkeystate("alt") = 0
Send,{Up}
else
Send,+{Up}
return
CapsLock & l::
if getkeystate("alt") = 0
Send,{Right}
else
send, +{Right}
return
It works perfectly everywhere.. except in MS Excel!
When I select a range of cells the selection marquee is there but no cell reference is taken in the formula.
Ex: Summing C3:C10 turns into =sum() no cells are actually selected in the formula.
if I keep trying up and down many times.. it shows, but never consistent.
Any idea how to fix this?
Thank you in advance
The problem comes from your shift key being released between the key presses.
Like for example try pressing keys like this in Excel and you'll see you're not actually selecting cells, you're just highlighting them:
Shift Down, Up Arrow, Shift Up
Shift Down, Up Arrow, Shift Up
Shift Down, Up Arrow, Shift Up
...
So you're going to have to keep shift pressed for the whole duration of your selection making process.
Here's what I could come up with:
CapsLock::Shift
#If, GetKeyState("CapsLock", "P")
*i::
if (GetKeyState("Alt", "P"))
SendInput, {Blind}{Alt Up}{Up}
else
SendInput, {Up}
return
*l::
if (GetKeyState("Alt", "P"))
SendInput, {Blind}{Alt Up}{Right}
else
SendInput, {Down}
return
#If
Or just like this to write it a lot cleaner with a ternary:
CapsLock::Shift
#If, GetKeyState("CapsLock", "P")
*i::SendInput, % GetKeyState("Alt", "P") ? "{Blind}{Alt Up}{Up}" : "{Up}"
*l::SendInput, % GetKeyState("Alt", "P") ? "{Blind}{Alt Up}{Right}" : "{Right}"
#If
So what's happening?
First we use the simple remapping syntax(docs) to remap CapsLock to Shift.
Then we create context sensitive hotkeys for I and L with #If(docs).
The hotkeys are only triggered if the physical state of CapsLock is down.
We need the physical state, because the logical state (which is default) was remapped to shift.
The hotkeys are created with the * modifier(docs) so they fire even if Shift and/or Alt is held down.
I switched the Send commands SendInput due to it being the recommended faster and more reliable send mode(docs).
And then about {Blind}. Normally, when you just send something with a send command, it automatically releases any modifiers you may be holding. But if you use the blind send mode(docs), this doesn't happen. So Shift is still held down all the time.
I would like to disable Shift Ctrl without disabling other shorcuts like Shift Ctrl A, or Ctrl A, or Shift A.
I have tried multiple combinaison of ^+:: return with and without :
- Up : ^+ Up:: return
- ~ : ~^+ Up:: return
- & : ~^ & ~+ Up:: return
Nothing work. Even when I start my script as admin it doesn work.
I want to rename Shift Ctrl because I have two keyboard languages and pressing Shift Ctrl change it. I already have the shorcut Windows Space so I don't need Shift Ctrl.
I have tried with ahk but I am open to any other way to solve this.
"^" is the modifier symbol for the Control key and "+" for the Shift key.
Modifier symbols are used only in key-combinations for modifying other keys.
Try also
+Ctrl Up:: return
or
Shift & Ctrl Up:: return
EDIT:
You can change or remove the combination that changes the keyboard language on Control panel --> Language, as shown in the comments below.
I have a snippet of code I copied into my clipboard. Pasting it out looks like this. Where[tab] is an actual tab indent
[tab]<header id="masthead" class="site-header">
[tab][tab]<h1>
[tab][tab][tab]<h2>
[tab][tab][tab][tab]<h3>
[tab][tab][tab][tab][tab]<h4>;
I want to press an autohotkey to automatically normalize the code snippet. So if there's a [tab] on every line, remove it.
Then convert each [tab] into 2 spaces [**]
<header id="masthead" class="site-header">
**<h1>
****<h2>
******<h3>
********<h4>;
So the general workflow is:
Copy code to clipboard
Press an autohotkey
Paste the newly formatted contents
Pseudocode for autohotkey would look like this
Dig through every clipboard content line by line
If every item shares an equal number of [tab] spaces, remove them entirely
Line by line, convert [tab] to [**] 2 spaces
; convert each tab into 2 spaces:
clipboard =
(
<header id="masthead" class="site-header">
<h1>
<h2>
<h3>
<h4>;
)
clipboard := StrReplace(clipboard, A_Tab, A_Space A_Space)
https://autohotkey.com/docs/commands/StringReplace.htm
okay problem solved I have everything I want now. I took the other source code snippet here on autohotkey forum
F9::
clipboard := StrReplace(clipboard, A_Tab, A_Space A_Space)
position := RegExMatch(clipboard, "\S")
test := RegExReplace(clipboard, "m)^[ ]{" . position - 1 . "}")
clipboard := test
As a reference, need to highlight the full line on code snippet like so
So all I have to do now is:
Copy the full code
Press F9
Paste into my notetaking app (dynalist.io with codesnippet support)
I have a virtual keyboard created in RealBasic.
When I press letters, numbers I append it to a textfield all its ok but, how do I delete characters from that textfield from current cursor position when I press "Delete" button from virtual keyboard?
To append letters or numbers to the textfields I use:
TextField1.Text = TextField1.text + me.Caption //to append caption
TextField1.SelStart = Len(TextField1.text) // to move cursor at the end of string
Paul's solution works if you only plan to delete the last typed character.
But beware: If you let the user also move the cursor left and right, you have to delete the text at the position of the cursor, of course. And if you also allow the user to select text, then it's even more complicated.
I suggest that your virtual keyboard simply send the typed key to the system as if the user had pressed the key. That way, the TextEdit field will do everything for you.
To make this work, however, you need custom solutions for each OS platform you want to support.
Let me know which platforms you plan to support and I'll see what I can find. I have some code for OSX but not for Windows, yet.
Doing what Thomas said means:
dim n as String = TextField1.Text
n = newText.left(TextField1.selStart) + n.right(n.len - textField1.selStart - 1)
textField1.text = n
Just lop off the last character:
TextField1.Text = TextField1.Text.Left(TextField1.Len-1)
Basically,
It's inspired by Vim I want to use a key(e.g Alt, F1) combination(+I J K L) to map to Arrow Keys
What is already done in Autohotkey
Ralt & j::send{Left}
Ralt & k::send{Right}
...
Now I take Alt+I as up etc,which is pretty fine for me But the problem comes when you press
Ralt+Shift+j (Suppose to select the last charater)
Ralt+Ctrl+j (Suppose to move a caramel text)
These kind of combination would not work and it just get overrided to basic move cursor to left
Even if I use if/while statement with GetKeyState, it doesn't gonna work
if GetKeyState("Shift","P")
Ralt+j::send +{Left}
This kind of stuff didn't work
Any Ideas on that ?It would make coding very efficient without having to move the right hand.
Thanks in advance.
You are missing 2 things:
Must use a # symbol when doing a context sensitive hotkey
The bottom section of code is using a + instead of the & you used previously.
See the below modification:
RAlt & j:: Send {Left}
RAlt & k:: Send {Right}
#If GetKeyState("Shift","P")
RAlt & j:: Send +{Left}
RAlt & k:: Send +{Right}
; Close with #If to remove the context or simply start another '#If GetKeystate ....'