Below script opens a browser to www.google.com
But the keys "ch" are sent to the editor window.
~c ::
~h::
If (GetKeyState("c","h") && GetKeyState("c","h")) {
Run, "www.google.com"
Return
}
Return
How can the script be amended so that no output text is sent to the editor ?
Alternatively can focus be removed from the current text editor (for example notepad) ?
I think one of these two versions does what you need:
Version 1
c::
h::
If (GetKeyState("c") && GetKeyState("h")) {
Run, "www.google.com"
}
Return
Version 2
~c::
~h::
If (GetKeyState("c") && GetKeyState("h")) {
Run, "www.google.com"
}
Return
Your mistakes:
Take a look at documentation of GetKeyState command. First function parameter is name of the key you wish to check and second parameter is mode in which GetKeyState command should work. In your example "h" parameter is incorrect parameter.
Also you don't need two returns.
Here ~c :: space will give you error. It should be like ~c::
Also, always use AutoHotkey and its documenatation from http://ahkscript.org/ (current uptodate version, new official website)! AutoHotkey and its documentation from autohotkey.com is outdated and you may have some problems using them!
Edit:
If the hotkey has prefix ~ then when the hotkey fires, its key's native function will not be blocked (hidden from the system). So, if we write ~c:: , when you press c then it will act as a hotkey in your script and also c will be send to active window. If we write c:: , when you press c then it will act as a hotkey in your script but nothing will be send to active window. Also look here in the table for more details.
Related
I am having some serious struggles fully grasping the control on activating windows and forcing their focus and foremost position.
In order to debug a larger script I made a separate script to test the use of WinActivate and again I am observing frustrating behaviour as it either all together ignores the title I have defined or is failing in some other way. In the smaller test script I am simply requesting that the window in which the hotkey was triggered be set as active after another action, specifically an input box
Below is the simple code for testing:
F10::
SetTitleMatchMode, 1
DetectHiddenWindows, Off
WinGetTitle, startTitle, A
msgbox % "Start Title = <" . startTitle . ">"
;WinActivate, startTitle
inputbox, mode, Test box, Testing,,260,160
sleep 500
WinActivate, startTitle
Return
This code does not properly activate the starting window. For example I execute the hotkey in an empty notepad window and upon submitting blank into the input box the focus becomes notepad++ on my second monitor. The second time I press the hotkey from within notepad (or another application) notepad does not lose focus. In a third execution I begin from notepad again and after the input box appears I switch the focus to another window. I again submit blank to the inputbox but that new window remains the focus and notepad is not activated or brought to the foremost position.
Can someone please explain to me what is going on with WinActivate?
I was having similar frustration with unexpected results making a windows script host file and I think I must be missing some fundamental detail in windows.
You are trying to activate a window that start with the literal text "startTitle".
You forgot(?) to either enter expression syntax with % or use the legacy way of referring to a variable %startTitle% (please don't use legacy).
Extra stuff:
You shouldn't specify SetTitleMatchMode and DetectHiddenWindows inside your hotkey statement. There is no need (unless there actually is) to set those every time you hit the hotkey. Just specify them at the top of your script once.
Both of them are useless for you though, below I'll show why. Also DetectHiddenWindows is already off by default.
WinGetTitle is not good to use for this. What you actually want to do is get the hwnd of the window you wish by using e.g. WinExist().
And then refer to the window by its hwnd. Much better than working with window titles, and impossible to match the wrong window as well. To refer to a window by its hwnd, you specify ahk_id followed by the hwnd on a WinTitle parameter.
And lastly, the concatenation operator . is redundant. Of course you may prefer to use it, but in case you didn't know, it can just be left out.
Here's your revised code:
F10::
_HWND := WinExist("A")
MsgBox, % "Start hwnd = <" _HWND ">"
InputBox, mode, Test box, Testing,,260,160
Sleep, 500
WinActivate, % "ahk_id " _HWND
Return
Goal:
Use the hotkey 'C' to mimmic 'New Email Window' in Outlook, similar to Gmail.
Attempt:
c::
SetTitleMatchMode, 2
If Not WinActive("Message")
Send, ^n
return
Problem:
This script does work, but then inside that 'New Email' Window the 'c' char is locked out, and I can't use it while typing.
Tried Solutions:
I tried adding and empty an 'else {}' but that does not seem to work. Thoughts?
Environment:
Windows 10 / Outlook 2016+
This is probably what you want,
SetTitleMatchMode,2
#if WinActive("Microsoft Outlook")
{
c::
Send, ^n
return
}
This way, it will allow to type the char 'c' anywhere, including the new email window. But, it will trigger if you are in the main Outlook window, opening a new email window for you.
This uses context-sensitive title matching to map C to CTRL+Nwhen "Microsoft Outlook" is in the window title:
SetTitleMatchMode 2 ; All #If statements match anywhere in title
#IfWinActive Microsoft Outlook
c::^n
#IfWinActiv
This worked. I think in my case it needed to know specifically what to do if the window was not active, and in my case it was to fire a regular 'c', I would have thought that logic was built in by default recognize.
c::
SetTitleMatchMode 2
IfWinActive, Outlook
Send, ^n
Else
send, c
return
$c::
If (WinActive("Microsoft Outlook") { ;may/may not be "Microsoft Outlook' use window spy to find out more
send ^N ; if you got that to work then dont mess with this part
} else {
send {c}
}
Return
Basically this checks if Outlook is active then if so sends ^N and if not it will send the character C.
However this isnt the best idea: creating single key hotkeys that are used for typing...
Better idea: you change the hotkey ( the part before "::` ) to something like $^!c
( the $ is so that any other hotkey sending c wouldn't activate this one )
Another aproach would be:
$~c::
If (WinActive(ahk_class "outlook.exe") { ; or something along the lines of that...
sleep 250
send ^N
}
Return
For the most part this does the same thing except it retains the functionality of the c key better, however it may cause issues with typing in outlook so once again,
Please consider either a non-typing single key hotkey such as Rcontrol for example. The ~ in the hotkey means don't revoke original key functionality, The sleep is added to ensure that when you are using the hotkey that the retained c character isn't added to your new email.
Hope this helped ( I am fairly certain that this works ) I don't use outlook so I don't know how well Outlook will respond to this type of thing, and haven't tested this out but I do know my AHK basics and did do function syntax double checking so good luck to you, read my cmments in the code because they are essential to these code snippets functionality.
you may want to add && If (Not WinActive("Message")) ;or whatwver the message window is called if the two snippets didn't work for your needs add this because your new message window may also be called outlook so this will interfere with the typing.
I found this working autohotkey (ahk) code from the website https://jacksautohotkeyblog.wordpress.com/2015/10/22/how-to-turn-autohotkey-hotstring-autocorrect-pop-up-menus-into-a-function-part-5-beginning-hotstrings/ .
::agin::
TextMenu("again,a gin,aging")
Return
::duh::
TextMenu("what,huh,you're joking")
Return
TextMenu(TextOptions)
{
StringSplit, MenuItems, TextOptions , `,
Loop %MenuItems0%
{
Item := MenuItems%A_Index%
Menu, MyMenu, add, %Item%, MenuAction
}
Menu, MyMenu, Show
Menu, MyMenu, DeleteAll ;Moved from MenuAction:
}
MenuAction:
SendInput %A_ThisMenuItem%{Raw}%A_EndChar%
Return
This is a hotstring script with menu. For example when I type agin I get a many with three options (again,a gin,aging) to choose. Now I want to write it something like this:
agin=again,a gin,aging
duh=what,huh,you're joking
qwe=qwe,qww,ere
Because I have a lot of hotstrings.
As time has passed, in the most recent version of AHK it became possible to do!
Use option x to allow expressions in the oneliner.
Either as :x:...:: OR as a group option above all lines: #Hotstring x
:x:agin::TextMenu("again,a gin,aging")
As nice as it would be, unlike AutoHotkey Hotkeys, I don't believe you can put anything other than replacement text on the same line of an AutoHotkey Hotstring. In other words,
::agin::TextMenu("again,a gin,aging")
would not work while,
::agin::
TextMenu("again,a gin,aging")
Return
does. It is a few more characters long, but not overwhelming.
[Key Mappings of New Media Remote]
http://i.stack.imgur.com/ivMSK.png
Using AutoHotkey I want to interrupt Keyboard Keys sent like AppsKey and Browser_Home and send another key instead. Unfortanately the best I can manage is to send a key as well as the key function.
F3::SendInput {a}
Browser_Home::SendInput {a}
Browser_Home::SendInput a
Browser_Home:: a
The first line 'F3 to a' works as intended; the F3 Key outputs the letter a.
The 2nd and 3rd line Browser_Home only launches Browser to Home.
The 4rd line launches the Browser_Home as well as outputting the letter a.
Anyone know what I'm doing wrong / know how to fix my script to output a without launching browser to home?
According to documentation under Hotkey:
$ is usually only necessary if the script uses the Send command to send the keys that comprise the hotkey itself, which might otherwise
cause it to trigger itself. The $ prefix forces the keyboard hook to
be used to implement this hotkey, which as a side-effect prevents the
Send command from triggering it. The $ prefix is equivalent to having
specified #UseHook somewhere above the definition of this hotkey
Try this and report back: $Browser_Home::SendInput {a}
So I'm trying to learn autohotkey scripts and the documentation is lacking at best. First, can authotkey read commands and perform actions and such inside a virtual machine? I have a windows host and a linux virtual machine running eclipse. I'd like to get a hostring (or a keyboard macro, either is fine) to put in some long (10+ lines) of text. Can that actually work in a VM or do I have to run autohotkey inside the VM for it to work?
As for implementing this, I have 2 problems. First, how do I display multiple lines of text from a keyboard macro? I know about the Send command, but I haven't figured out how that works. I have this:
:*:insert::
(
Text to
insert
goes here
and more here
)
And this works fine except in notepad++, it inserts consecutively more tabs, so it will look like
Text to
insert
goes here
and more goes here
And so in my many line macro, by the end it's several pages scrolled off the screen.
As for keyboard macro, changing the above to
#c::
Send{Raw} (
stuf
to send
)
Return
This gives syntax errors and I have no idea what the correct way of doing that would be. Should I just stick with using hotstrings?
You could try to modify the clipboard and use control + v to paste it into the proper place.
Try:
#c::
{
clipboard := "yourtext`nMultiline`nYet another line"
send, {control down}v{control up}
return
}
The first 'insert' hotstring is correct,
however, you would get the same result that you describe,
if you performed manually, the keypresses that the hotstring is sending.
To get the output you want,
you need to change these two settings:
Settings, Preferences...,
Auto-Completion,
untick: Enable auto-completion on each input
Settings, Preferences...,
MISC.,
untick: Auto-indent
the '#c' hotstring is amended below:
#c::
Send {Raw}
(
stuf
to send
)
Return