How to catch and prevent alt code character from printing? - autohotkey

How to catch and prevent an Alt Code character from printing?
OS: Windows 10 Enterprise
AHK Ver: 1.1.30.03
My AutoHotkey script implements additional paste functionality using the Right Alt + Shift keys combined with a qualifying Numpad key. For this to work, I need to press the keys in the following order: Right Alt + [Desired Numpad key] + Shift.
The script :
RAlt & Shift::
; Place the cursor at the start of the pasted text
If GetKeyState("Numpad5", "P") {
Clip := Clipboard
SendInput %Clip%
Sleep 10
Loop, Parse, Clip
SendInput {Left}
}
...other Numpad # functionalities here using Else If's...
Return
The problem is that after performing a shortcut, the corresponding Alt Code character will print followed by the clipboard contents. I've been able to resolve the issue by adding a backspace command :
RAlt & Shift::
; Place the cursor at the start of the pasted text
If GetKeyState("Numpad5", "P") {
Clip := Clipboard
SendInput %Clip%
Sleep 10
Loop, Parse, Clip
SendInput {Left}
SendInput {Backspace}
}
...other Numpad # functionalities here using Else If's...
Return
But I want to "catch" this Alt Code character and prevent it from printing instead of deleting it afterwards. The solution shouldn't prevent me from using Alt Codes while the script is running. Is there a "buffer" containing the Alt Code character that I could clear out before printing the clipboard contents?

Related

How to make script to paste something in with AutoHotKey

I'm trying to make a script in AutoHotkey where, when I press Numpad 1, it presses the slash button, then pastes in some text, let's say "hello world", and then presses enter, but I can't figure out how. Can someone help?
Welcome to Stack Overflow.
In the future, try to at least show what you tried. All of this should be accomplished pretty easily by e.g. looking at the beginner tutorial combined with a quick Google search.
But well, here it is:
Numpad1::
Clipboard := "/hello word"
SendInput, ^v{Enter}
return
Numpad1:: creates the hotkey label.
Clipboard:= ... puts something into the clipboard.
SendInput sends input.
^v means Ctrl+v.
{Enter} means the enter key (could've possibly appended `n (line feed) into the string as well).
Return stops the hotkey label's code execution (in other words, ends the hotkey's code).
Assuming that you already have some text copied inside your clipboard before pressing the numpad1, the following code will work.
Numpad1::
Send, /^v ; ^ means ctrl key,
Send, {Enter}
return

CTRL key is held down in AutoHotKey

Pressing the CTRL+Numpad 7 key, it displays the text I want, but the CTRL key remains pressed.
How do I prevent it from being pressed after executing the command?
My AutoHotKey code is something like this
Ctrl & Numpad7::
SendInput `
(
some text
multiline
)
return
I had the same problem and I fixed it with this something like this :
!Crtl Up:: send {Ctrl Down}
try this in the end of the script(the line after return).

Hotkey reassigning macro not working

I am using AutoHotkey to re-assign some hotkeys in Dr. Explain. The macro executes to the point of the message but the actual new hotkeys aren't working.
Here's the script:
WinActivate, DRAFT_Complete Jazzit Help Masterfile* - Dr.Explain (Licensed to: Accountants Templates Inc.)
MsgBox Normal --> Alt + A and Normal - emphasis --> Alt + S
Return
;Change keystrokes for normal and normal-emphasis
#Inputlevel 1
^+n::!a
^+6::!s
#Inputlevel 1
#IfWinActive
Not sure if I'm missing anything.
Defines hotkeys CtrlShiftN and CtrlShift6 for windows containing "Jazzit" in their title
SetTitleMatchMode 2 ; All #If statements match anywhere in title
#IfWinActive Jazzit
F1:: MsgBox Normal --> Alt + A and Normal - emphasis --> Alt + S
^+n::send !a
^+6::send !s
#IfWinActive
The remapping format (i.e., not using send) passes along all modifier keys:
^+n::!a ; sends Alt+Shift+Ctrl+A
^+6::!s ; sends Alt+Shift+Ctrl+6

How to send CTRL or ALT + any other key?

I have powershell script which will open web page (Selenium) and set focus on the "Message" box. Now, I want to simulate Ctrl+V to paste my data from clipboard. Is there any way to do that in pure powershell? An C# code that can be used in powershell function would be also great.
You can send the modifier key combination Ctrl+C like this:
[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
[System.Windows.Forms.SendKeys]::SendWait("^{c}")
From article Converting the Windows Script Host SendKeys Method
The modifier keys are:
Key | Code
-----------
SHIFT +
CTRL ^
ALT %
Other keys you might want:
Key | Code
-----------
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER}or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}
Keypad add {ADD}
Keypad subtract {SUBTRACT}
Keypad multiply {MULTIPLY}
Keypad divide {DIVIDE}
A bit dry to read, but maybe reading C#'s docs on using what's on the clipboard might help:
http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard%28v=vs.110%29.aspx

Autohotkey - Undo entire macro instead of single commands (Windows 7)

I tried searching for an answer beforehand but didn't find what I was looking for. Apologies in advance if this has been answered before.
I do some web work and created a macro in AHK that binds Ctrl+Shift+B to the HTML equivalent of adding bold tags around a text selection.
The flow is:
cut (ctrl+x), type <b>, paste cut text (ctrl+v), type </b>.
The macro runs fine, but sometimes I want to undo it. However, whenever I press Undo (ctrl+z), I'm left pressing the command 4 times, with each press reverting 1 of the commands posted above.
Is there a better way to write my AHK macro so that I'm able to undo the entire macro in 1 keypress? Any tips would be great. For Windows 7 if that makes a difference.
I've added the macro below.
^+b::
{
SendInput ^x
SendInput <b>
SendInput ^v
SendInput </b>
return
}
Edit: & #60; is the hmtl equiv on '<', but I was worried that this post would convert the HTML tags instead of showing the characters. Fixed.
Sorry about that, I tend to use a combination of notepad, notepad++, internet explorer to access a CMS. –
I think adding a delay and rewriting the AHK macro in the following way has solved my issue. Thanks for the help!
^+b::
clipboard =
SendInput ^x
ClipWait,1
if ErrorLevel
{
MsgBox, The attempt to copy text onto the clipboard failed.
return
}
SendInput < b >%clipboard% < /b>
return
Try this instead:
^+b::
{
Clipboard =
SendInput ^c
ClipWait, 1
Clipboard = <b>%Clipboard%</b>
SendInput ^v
return
}
Because the only thing you are doing is a paste, undoing this will undo both of the bold tag. The clipboard edits are not registered as an "undo" action.
Here is some code:
^+b::
Click, 2 ; Highlight current word
Send, ^x
ClipWait, 1 ; ADDED to wait for clipboard
SendInput, <b>^v<`/b>
Return
!b::
Send, ^{z 4}
Return
or
!b::
Send, "command to search backwards" for </b>
Send, {Del}
Send, "command to search backwards" for <b>
Send, {Del}
Return
or
!b::
Send, {Home}+{end} ; [Home] then [Shift][End] to highlight current line
Send, ^h ; Or any other command to start find/replace
Send, <b>^v<`/b>{Tab}^v{Enter} ; or what is required to replace in current section only...
Return