I have the following script setup to change an environment variable (Mirus_Active_Directory) when I press Win+i. It works fine in Windows 7, but does not seem to work on Windows 10.
How can I modify the code to make it work with Windows 10?
Thanks
SetTitleMatchMode RegEx
return
#IfWinActive ahk_class ExploreWClass
#i::
SetPath()
return
#IfWinActive ahk_class CabinetWClass
#i::
SetPath()
return
#IfWinActive
; Opens the command shell 'cmd' in the directory browsed in Explorer.
; Note: expecting to be run when the active window is Explorer.
;
SetPath()
{
; This is required to get the full path of the file from the address bar
WinGetText, full_path, A
; Split on newline (`n)
StringSplit, word_array, full_path, `n
; Take the first element from the array
full_path = %word_array1%
; strip to bare address
full_path := RegExReplace(full_path, "^Address: ", "")
; Just in case - remove all carriage returns (`r)
StringReplace, full_path, full_path, `r, , all
IfInString full_path, \
{
RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SYSTEM\CurrentControlSet\Control\Session Manager\Environment, Mirus_Active_Directory, %full_path%\
RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SYSTEM\ControlSet001\Control\Session Manager\Environment, Mirus_Active_Directory, %full_path%\
EnvUpdate
}
}
Related
Warning: I'm very new to this.
I'd like to make Google searches quicker by assigning a hotkey to search a text selection (in web browser) and surrounding that search with quotes (to get exact matches).
I've tried using bits of code I have found, but so far I can only search the selected text on Google, but don't know how to surround the selected text in quotes in the search.
^!d:: ;
prevClipboard := ClipboardAll
SendInput, ^c
ClipWait, 1
if !(ErrorLevel) {
Clipboard := RegExReplace(RegExReplace(Clipboard, "\r?\n"," "), "(^\s+|\s+$)")
If SubStr(ClipBoard,1,7)="http://"
Run, % Clipboard
else
Run, % "https://www.google.com/search?q=" Clipboard
}
Clipboard := prevClipboard
return
This simply opens a google search with the clipboard.
I cannot find out how to make it so "Clipboard" is searched instead of Clipboard.
Any suggestions? Thanks!
Run is a command and variables in commands have to be enclosed in percent signs.
To include an quote, specify two consecutive quotes twice:
Run, http://www.google.com/search?q=""%Clipboard%""
If you want to do a "Phase google search" from any Selected Text (And From Out Everywhere, on your Computer System.)
Then you can try this AHK Script.
you can [Select any Text] and then you can click the [F1] key from your Keyboard Device.
The Computer Find automatic out where it can do the Query Search (us 100x results) and what Browser it must use.
Example1.ahk
;#notrayicon
#SingleInstance force
GroupAdd, Browser, ahk_class Chrome_WidgetWin_1 ; Chrome or Iron
GroupAdd, Browser, ahk_class IEFrame ; Internet Explorer
GroupAdd, Browser, ahk_class MozillaWindowClass ; FireFox
GroupAdd, Browser, ahk_class ApplicationFrameWindow ; Edge
; here you can change the variable into exact search [
quote1 = "
; here you can change the variable into exact search ]
quote2 = "
; here you can change the variables intitle: - inurl: - inanchor: - allinurl: - allinanchor:
insearch = allintitle:
; + = Shift
; ! = Alt
; ^ = Ctrl
; # = Win (Windows logo key)
esc::exitapp ;You can click the (esc) key to stop the script.
f1::
If WinActive("ahk_group Browser")
{
sendinput ^c ;copy the selected text to clipboard memory
sleep 150
sendinput ^t ;CTRL+t make a new tab + goto address bar - use CTRL+L for the active tab + goto address bar
sleep 150
texta = https://www.google.com/?gfe_rd=cr&gws_rd=cr#q=%insearch%%quote1%
textb = %clipboard%%quote2% ;selected text
textc = &lr=lang_us&hl=us&num=100 ; google parameters
clipboard=%texta%%textb%%textc%
sleep 150
sendinput ^v ; paste the selected text
sleep 250
send {enter}
clipboard=%textb%
} else {
sendinput ^c ;copy the selected text to clipboard memory
sleep 150
texta = https://www.google.com/?gfe_rd=cr&gws_rd=cr#q=%insearch%%quote1%%quote1%
textb = %clipboard%%quote2%%quote2%%quote2% ;selected text
textc = &lr=lang_us&hl=us&num=100 ; google parameters
clipboard=%texta%%textb%%textc%
run %clipboard%
clipboard=%textb%
}
return
How can I bind several keys to the same command in AutoHotKey?
Example: I have this command:
spamLimit(limitTime)
{
StringReplace, key, A_ThisHotkey, $, , All
send %key%
sleep limitTime
}
I would like to bind several to this command, with the same parameter value:
a::spamLimit(500)
b::spamLimit(500)
c::spamLimit(500)
p::spamLimit(500)
d::spamLimit(500)
e::spamLimit(500)
Simplest solution:
a::
b::
c::
p::
d::
e::
spamLimit(500)
return
You can use Hotkey to define hotkeys on the fly:
; Thanks engunneer: autohotkey.com/board/topic/45636-script-to-prevent-double-typing/?p=284048
; Thanks throwaway_ye: https://www.reddit.com/r/AutoHotkey/comments/54g40q/how_can_i_bind_several_keys_to_the_same_command/d81j0we
; The following part must be located in the auto-execute section,
; i.e. the top part of the AHK script.
keylist = 1234567890qwertzuiopasdfghjklyxcvbnm
Loop, parse, keylist
{
Hotkey, $%A_LoopField%, spamLimitNoParam
}
Return
; This can be located anywhere in the AHK file
spamLimitNoParam:
spamLimit(200)
Return
This is equivalent to the solution Bob pointed to:
$a::
$b::
$c::
$d::
$e::
$f::
$g::
$h::
$i::
$j::
$k::
$l::
$m::
$n::
$o::
$p::
$q::
$r::
$s::
$t::
$u::
$v::
$w::
$x::
$y::
$z::
$0::
$1::
$2::
$3::
$4::
$5::
$6::
$7::
$8::
$9::
spamLimit(200)
I use autohotkey version: 1.0.48.05 (because I stick with activeaid).
The script to read the current path is as follows (and worked until Win 7).
; Get full path from open Explorer window
WinGetText, FullPath, A
; Clean up result
StringReplace, FullPath, FullPath, `r, , all
FullPath := RegExReplace(FullPath, "^.*`nAddress: ([^`n]+)`n.*$", "$1")
How I suspect that while switching to Win10 it seems that I also switched the language.
If I MsgBox out the %FullPath% before cleaning with
WinGetText, FullPath, A
MsgBox %FullPath%
I see amongst other strings (obvoíously separated by CR):
Adresse: V:\Vertrieb\Prospects\MyFile
so how do I need to adjust the regexp to extract that very string!
Best regards
Hannes
#IfWinActive, ahk_class CabinetWClass ; explorer
F1:: MsgBox, % GetActiveExplorerPath()
; or
F2::
ActiveExplorerPath := GetActiveExplorerPath()
MsgBox, % ActiveExplorerPath
return
#IfWinActive
GetActiveExplorerPath() {
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=69925
explorerHwnd := WinActive("ahk_class CabinetWClass")
if (explorerHwnd)
{
for window in ComObjCreate("Shell.Application").Windows
{
if (window.hwnd==explorerHwnd)
return window.Document.Folder.Self.Path
}
}
}
Try:
f1::MsgBox % Explorer_GetSelection()
Explorer_GetSelection(hwnd="") {
WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
WinGetClass class, ahk_id %hwnd%
if (process = "explorer.exe")
if (class ~= "(Cabinet|Explore)WClass") {
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd)
path := window.Document.FocusedItem.path
SplitPath, path,,dir
}
return dir
}
It takes me so much time to find the best solution (for me).
Maybe it will work for you as well.
ControlClick, ToolbarWindow323, A
ControlGetText, path, Edit1, A
Msgbox, %path%
Background:
So I use the Explorer tool Q-Dir (link to homepage).
In Q-Dir you can bookmark folder you want to access regularly.
You can shortcut to those bookmarks by pressing Ctrl + Q. This opens a jumplist of your bookmarked folders.
So I want to open my projects folder which is named "Kundenprojekte" (customer projects).
Pressing "K" while said jumplist is open, opens this folder in the current tab.
So my problem occurs here:
This whole process is what I want to map with AHK to let's say WinKey + B.
This is my code so far:
#b::
qdirId := WinExist("Q-Dir 5.98.9") ; I don't know if this works I got some
; inspiration by another AHK script
if (qdirId = 0) {
MsgBox Q-Dir ist nicht geöffnet. ; Q-Dir is not open.
IfWinExist, "Q-Dir 5.98.9"
{
WinActivate, "Q-Dir 5.98.9" ;I know this doesn't work plz help
SetKeyDelay 10,1000
Send, ^{Q}
SetKeyDelay, 10
Send {K}
return
}
}
return
Yes , so far there is no "else" to IfWinExist. And I don't think there will be because I would need to run Q-Dir as administrator (due to UAC preventing writing operation to my C: drive) But that is of no concern (because I usually start Q-Dir as my first programm after booting).
The main issue I have is getting "send Control + Q" then "K" to work.
I got it to send "K" but not once was "Ctrl + Q" recognized.
Any idea what I do wrong?
Thank you in advance :)
SetTitleMatchMode, 2 ; The window's title should contain "Q-Dir 5.98.9"
#b::
qdirId := WinExist("Q-Dir 5.98.9")
if (qdirId = 0)
{
MsgBox Q-Dir ist nicht geöffnet. ; Q-Dir is not open.
return ; stops code from going any further, to the lines below
}
; otherwise:
WinActivate, Q-Dir 5.98.9
WinWaitActive, Q-Dir 5.98.9 ; important
SetKeyDelay 10,1000
Send, ^{Q}
; Try also:
; Send, {CTRLDOWN}q{CTRLUP}
; SendEvent {CTRL DOWN}{q DOWN}{CTRL UP}{q Up}
SetKeyDelay, 10
Send {K}
return
https://autohotkey.com/docs/commands/SetTitleMatchMode.htm
I have this simply script in Autohotkey:
:*:teams::
(
milan
juventus
inter
roma
lazio
napoli
mantova
)
When i type teams on Notepad my output is the list of teams (milan, juventus..)
if i use a physical keyboard to type teams this script work for me
, but if use a virtual keyboard to type teams i have no list on Notepad:
and if i run the script to type teams automatically
WinWait, *new 2 - Notepad++,
IfWinNotActive, *new 2 - Notepad++, , WinActivate, *new 2 - Notepad++,
WinWaitActive, *new 2 - Notepad++,
MouseClick, left, 133, 117
Sleep, 100
Send, squadre
the script doesn't replace teams with the list of teams
Why the script works only if i type with a physical keyboard?
is there a solution to replace words, sentences with my scripts without using physical keyboard?
Sorry if i am noob
You can use the Input command.
loop {
While !RegexMatch(strCapture, "teams$") {
Input, strUserInput, V L1, {BackSpace} ; V: visible, L1: Character length 1
If ErrorLevel = Endkey:BackSpace
strCapture := SubStr(strCapture, 1, StrLen(strUserInput) - 1)
else
strCapture .= strUserInput
; tooltip % ErrorLevel "`n" strUserInput "`n" strCapture "`n" ; enable this to see what actually happens
}
SendInput,
(Ltrim
{Backspace 5}
milan
juventus
inter
roma
lazio
napoli
mantova
)
strCapture := ""
}