I'm getting an invalid hotkey error when I type this in
^u & i::
Send, Hello World
return
I just want the script to activate when I press CTRL+u+i
Easiest way to achieve this would be creating a context sensitive hotkey with #If(docs) like this:
#If, GetKeyState("Ctrl", "P") ;begin context sensitive hotkeys
u & i::
SendInput, Hello World
return
#If ;end context sensitive hotkeys
Related
This issue seems to only occur in this one program.
I have the hotkey Shift+a set in this programs hotkey editor dialog, I want to trigger it in AHK using Rshift and w;
RShift & w::
SendInput, +{a}
Return
For the life of me, it will not work. I press Rshift and w and nothing happens at all. Triggering the hotkey manually by pressing shift and a works just fine.
The strange thing is the following works:
LCtrl & w::
SendInput, +{a}
Return
So does this:
w::
SendInput, +{a}
Return
I also tried to send Rshift back up before triggering the hotkey, no luck:
RShift & w::
SendInput, {RShift up}
SendInput, +{a}
Return
Is there a rule that says you cant use the same modifier as the target hotkey in the trigger that I missed?
please dont suggest that I use other modifier keys, shift +[key] is all that I have left.
Any help would be greatly appreciated!
Firstly, you shouldn't use a custom hotkey combination when a modifier exists (unless you have a good reason to):
For standard modifier keys, normal hotkeys typically work as well or better than "custom" combinations. For example, <+s:: is recommended over LShift & s::.
And secondly you shouldn't escape keys in a Send(docs) command that don't need escaping:
Enclosing a plain ASCII letter (a-z or A-Z) in braces forces it to be sent as the corresponding virtual keycode, even if the character does not exist on the current keyboard layout. In other words, Send a produces the letter "a" while Send {a} may or may not produce "a", depending on the keyboard layout. For details, see the remarks below.
And then about the problem itself:
I of course can't know if this will work, but I'd simply try the following:
>+w::a
This would work because because the remapping syntax actually uses the blind sendmode.
Alternatively, you could, of course, just manually use the blind sendmode:
>+w::SendInput, {Blind}a
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)
Is there any way to override ctrl-s ctrl-q implementation on c ? I want to make a shell where when you press ctrl-s it freezes the program. I've seen int tcflow(int fildes, int action); but how can I trigger this one when someone presses ctrl-s?
stty stop undef start undef
disables default ^S + ^Q behavior.
You don't have to. The terminal is in charge of this. If your process in the foreground process on the terminal then action is automatically taken. This is what POSIX terminals are intended for. Find resource on the web about "writing a shell".
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.
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