Autohotkey: Hotkeys on Firefox not doing what they're supposed to - firefox

I just want W to correspond to the Up Arrow key and S to correspond to the Down Arrow key, and work just like they do, and for A/D to move the focus to the last/next tab.
When i hold S, the page skips down erratically and then Firefox opens the "Save as" window multiple times.
When i hold W, the page skips up erratically and then multiple tabs are closed.
D does what it's supposed to, and A straight up doesn't work.
#IfWinActive ahk_exe firefox.exe
w::
Send {Up} ; Move page up.
s::
send {down} ; Move page down.
a::
send, ^{pgup} ; Go to tab on the left.
d::
send, ^{pgdn} ; Go to tab on the right.
#IfWinActive
Return
What exactly is happening? It should work normally but it isn't.

#IfWinActive ahk_exe firefox.exe
w:: Send {Up} ; Move page up.
s:: send {down} ; Move page down.
#IfWinActive ; turn off context sensitivity
The above examples are known as single-line hotkeys because each consists of only one command.
To have more than one command executed by a hotkey, put the first line beneath the hotkey definition and make the last line a return. For example:
#n::
Run http://www.google.com
Run Notepad.exe
return
https://autohotkey.com/docs/Hotkeys.htm#Intro

Related

Left alt and right alt produce different results

My script:
#MenuMaskKey vkFF
#SingleInstance Force
SendMode Input
SetTitleMatchMode Regex
#IfWinActive ahk_exe (chrome|msedge).exe
!l::Send ^{Tab}
#IfWinActive
In Chrome, when using !l with the left alt, ctrl+tab is sent without side effects, however, if using !l with the right alt instead, ctrl+tab is sent and the ctrl key is never released, if I press j after that, the download page will be opened.
Does anyone know the root cause of this behavior and how to fix this?
AHK version: 1.1.33.10

How to detect focus into Microsoft Outlook Search field with AutoHotKey

Question
How do I program AutoHotKey to detect the Microsoft Outlook Search field at the top of the window, so as to only enable hotkeys when outside of that window? That search field looks like this:
Details
I'm intending to add single-character hotkeys similar to what gmail has: https://support.google.com/mail/answer/6594?hl=en#zippy=%2Cactions , notably the # keybinding for deletion. I'm basing my experimentation with AutoHotKey scripts such as this one:
https://github.com/pimlottc-gov/gmailkeys/blob/master/gmailkeys-2013.ahk#L37
That script limits its hotkeys to the main Outlook window using #IfWinActive:
#IfWinActive, - Outlook ahk_class rctrl_renwnd32, NUIDocumentWindow ;for Outlook 2013, uncomment this line
However, if I do not change the above #IfWinActive statement, and then add the # hotkey via:
+3::Send {Delete} ; Means "#" key: Delete selected message(s)
then when running the script, then clicking in the above Search field, then typing #, then of course it sends the Delete key into that field, instead of just passing the # into the search field.
I've hacked around this by rebinding both Ctrl+e and / (the latter being the Gmail binding for searching/filtering) to a temporary input popup where I type in the search expression, and then let AutoHotKey type it into the field. But this of course is a hack:
; Search for some expression
;
; Hack: We have to popup an input dialog box, prompt for the
; search expression, and then when done, type it into the
; underlying search field. This is needed to avoid having other
; single-key bindings get "eaten" when needing to type into the
; Outlook search field, as as of 2021-05-23 I could not find a way
; to detect that specific input field.
;
^e::
/::
; Save current active (Outlook) window so we can return to after prompting for the search expression:
WinGet, winid ,, A ; <-- need to identify window A = active
; Prompt for the search expression:
InputBox, search_expr, Search Expression, Enter the search expression.
; Return to the Outlook window:
WinActivate ahk_id %winid%
; If the user presses Escape or clicks on the Cancel button, do nothing:
if (!ErrorLevel) {
; but if we are doing the search:
; Get into the search field:
Send ^e
; Select all prior text so we can wipe it out:
Send ^a
; ... by typing in all of the expression:
Send %search_expr%
; then do the search:
Send {Enter}
}
return
No matter where I click around in the main Outlook window, Window Spy (app that comes with AutoHotKey), the class always stays the same.
AutoHotkey version: 1.1.33.08
Note that Shift+3 only happens to produce a # on your keyboard layout. It would be more correct to actually use the # key as the hotkey.
Also, the code you're referencing is very legacy AHK. Quite a few things in there that don't belong to modern AHK.
I'd maybe also recommend just doing this with a context sensitive hotkey.
This way you'll retain the # key's native functionality.
The context sensitive hotkey could be done like this:
SetTitleMatchMode, 2
#If, WinActive("A") == WinExist("- Outlook ahk_exe OUTLOOK.EXE") && !SearchBarFocused()
#::SendInput, {Delete}
#If
SearchBarFocused()
{
ControlGetFocus, ctrl
return InStr("RICHEDIT60W1,RichEdit20WPT1", ctrl)
}
I'm also checking if Outlook is actually the active window first. Might be kind of redundant, but makes it so the remap couldn't be active in some other window that could have a control by that name.
I found the solution after some experimentation (including simplification from per 0x464e's answer), and essentially reversing the logic, somewhat, at https://github.com/pimlottc-gov/gmailkeys/blob/master/gmailkeys-2013.ahk#L76 via this:
; Outlook-specific Hotkeys:
;
; Reference material used in this implementation:
; https://autohotkey.com/board/topic/38389-archiving-email-in-outlook-with-a-single-keystroke/
;
; As best I can tell, the window text 'NUIDocumentWindow' is not present
; on any other items except the main window. Also, I look for the phrase
; ' - Outlook' in the title, which will not appear in the title (unless
; a user types this string into the subject of a message or task).
#IfWinActive - Outlook ahk_class rctrl_renwnd32, NUIDocumentWindow
#::
if (SentNormalKeyInOutlookEditControl("#"))
{
return
}
Send {Delete} ; Delete selected message(s)
return
#IfWinActive
SentNormalKeyInOutlookEditControl(normal_key)
{
; Find out which control in Outlook has focus
ControlGetFocus, currentCtrl
; ; set list of controls that should respond to specialKey. Controls are the list of emails and the main (and minor) controls of the reading pane, including controls when viewing certain attachments.
; ; The control 'RichEdit20WPT1' (email subject line) is used extensively for inline editing. Thus it had to be included in bad_ctrl_list.
; ctrlList = Acrobat Preview Window1,AfxWndW5,AfxWndW6,EXCEL71,MsoCommandBar1,OlkPicturePreviewer1,paneClassDC1, RichEdit20WPT2,RichEdit20WPT4,RichEdit20WPT5,RICHEDIT50W1,SUPERGRID1,_WwG1
bad_ctrl_list = RICHEDIT60W1,RichEdit20WPT1
; RICHEDIT60W1 is the search field at the top of the window
if currentCtrl in %bad_ctrl_list%
{
; MsgBox, BAD Control with focus = %currentCtrl% normal_key = %normal_key%
Send %normal_key%
return 1
}
return 0
}
Edit 2021-05-25 06:58:23: Replace legacy "+3" with "#" per 0x464e's answer.
Edit 2021-05-25 08:20:09: Prevent " - Message" windows from receiving the hotkeys (separate message windows, not main window)

Mapping RightAlt+Ctrl+a to send Ctrl+Delete?

I have the following map:
>!+a::SendInput,+{Delete}
It's supposed to send Ctrl+Delete (delete word after cursor) when I press RightAlt+Ctrl+a but instead it's sending a Ctrl+Alt+Delete signal so it's bringing up the Windows 7 menu of shutdown, start task manager etc.
How can I send the right signal?
Appreciate any help!
The problem you are facing is that Ctrl + Alt + Delete is hard coded and is uninterruptible. There's simply no way around it, if you press that sequence, even with the Command BlockInput enabled, Windows will re-enable input and execute the command...
Try:
>!^a:: ; + symbol is Shift ^ represents Ctrl key
KeyWait, RAlt ; Waits for Right Alt to be released before Ctrl Delete is sent
SendInput,{Ctrl Down}{Delete}{Ctrl Up}
Return
An alternative although it works the exact same way:
>!^a::
While (GetKeyState("RAlt", "P"))
Continue
SendInput,{Ctrl Down}{Delete}{Ctrl Up}
Return
I'll continue to pursue other options.. at the moment I can I think of no better way to do this.

script for focusing on a highlighted text

What is wrong with my script?
Context: Inbox folder of Outlook. I want to click (focus) just only one email (the one with the gray color), but my script ALSO "colors" all emails the are above it. I'm not sure what is the matter.
#IfWinActive ahk_class rctrl_renwnd32
+F7::
PixelSearch, Px, Py, 14,98,754,962, 0xE1E1E1, 3, Fast
if ErrorLevel
MsgBox, That color was not found in the specified region.
else
Click, %Px%, %Py%
return
#IfWinActive
It seems that you are oh, say, scrolling or moving the cursor around in the preview panel, and now you want to jump the cursor to that same email's entry in the mailbox listing.
If this be the case, then here is a possible solution for you:
Okay, so we know that by default, whatever message you are viewing in the preview pane should be the highlighted entry in the mailbox list. That means all we have to do is to set focus to the mailbox list pane - when that pane receives focus, then the highlighted entry should be able to receive your immediate keyboard commands since it is already selected.
Therefore, all you need to do with your ahk script is create a hotkey that sets focus to the mailbox pane. Use your window spy to spy the class of the mailbox pane and just set focus to it. You shouldn't have to worry about colours at all.
Maybe something like this for Office 2010:
+F7::
ControlFocus, SUPERGRID2, ahk_class rctrl_renwnd32
return
or, for Office 2013:
+f7::
ControlFocus, OutlookGrid1, ahk_class rctrl_renwnd32
if ErrorLevel
MsgBox, You don't seem to be in context.
return
Or, instead of hacking the window, you could just push ctrl+1 - Outlook has a built-in keyboard command to set focus to the mailbox list.

Binding to Ctrl-Shift in AutoHotKey

I want to use AutoHotKey to bind a command to Ctrl+Shift, in the same way that Windows detects it in order to change text direction from right-to-left to left-to-right. That is: I want it to be invoked when Ctrl+Shift is let go, and only if no keys were pressed between pressing Ctrl+Shift and letting them go.
I bound a hotkey on ^~ Shift Up and I expected it to behave the same way as when Windows binds to it for changing the text direction. But, I found that it gets invoked even in cases where I don't want it to be invoked.
For example, I could be selecting a few words by pressing Ctrl and Shift, and then using the arrow keys. Then I let go of Ctrl and Shift and the hotkey gets invoked. I don't want this. I want a hotkey that gets invoked only if I held nothing else then Ctrl and Shift. If I use any other keys, I want the hotkey not to be invoked.
Is there a way to do this with AHK?
#InstallKeybdHook
Hotkey, ^LShift Up, ControlShiftUp
Return
ControlShiftUp:
if (A_PriorKey != "LShift") ; [v1.1.01+]
return
; do something
msgbox hi
Return

Resources