I'd like a hotkey that changes a s to a ลก if s is hold down for a time. The "s" key doesn't work anymore with my version. Any ideas how to fix this?
s::
If (KeyWait,s,T0.3){
If ErrorLevel
Send {U+0161}
}
return
return
I use AHK 1.1.33.10 on a Win10 machine. The script is saved with ANSI coding.
$s:: ; The $ prefix forces the keyboard hook to be used
KeyWait, s, T0.3
If ErrorLevel
{
KeyWait, s ; waits for s to be released
Send {U+0161}
}
else
Send s
return
https://www.autohotkey.com/docs/commands/KeyWait.htm
Related
After a month of trial and error, I've finally found a solution!
How to remap Middle mouse button something else?
If you don't have a three-button mouse, this is a must-have for blender (esp. Laptop)
I'm aware of "emulate 3 button mouse" in Preference>>Input.
But if you check that option then you won't be able to 'Select loop'
which uses ALT leftClick.
What if you could remap Mbutton to any other key you rarely use?
Yes you can!
Nice to see that you tried it yourself.
But here's how a context sensitive remap is actually done:
#IfWinActive ahk_class GHOST_WindowClass
LWin::MButton
#IfWinActive
This script will allow you to remap Mbutton with other key, such as LeftWin.
;~--------------------------------------------------------------------------------------
#IfWinActive ahk_class GHOST_WindowClass ; Blender's class
$LWin:: ; "$" this allows to send the trigger key in a working script***
loop
{
if getkeystate("LWin", "p") ; if a button is Physically held down by the user.
{
send, {MButton DOWN}
}
else
{
send, {MButton UP}
;~ MsgBox, Blender is active ; You dont need this.
return
}
}
#IfWinNotActive ahk_class GHOST_WindowClass ; Other than blender (I'm aware of other methods, but this works for me!)
Send, {LWin} ; *** like here I'm able to use Left Win again without triggering the script.
;~ MsgBox,Blender isnt active ;; You dont need this.
return
;~ --------------------------------------------------------------------------------------
I want to write an AutoHotkey script which loop a key X number of times.
For example, here's is a script which overwrites the function of ENTER key with function of F2 key in File Explorer.
#IfWinActive ahk_class CabinetWClass
Enter::
Send, {F2}
#IfWinActive ahk_class CabinetWClass
Enter::
Send, {ENTER}
#IfWinActive
The goal is to press ENTER to rename a select file, and then press ENTER to confirm the rename. Pressing ENTER on the same file that have just been renamed should send F2 key again (In case there is typo error).
Currently the second block doesn't work as I'm sending the same key, how to fix this?
The KeyWait command is your friend in this case.
There is still room to improve on how you handle the second Enter
#IfWinActive ahk_class CabinetWClass
$Enter::
sleep,100 ; giving time to detect the first Enter
Send, {F2}
Keywait, Enter, T5 D ; wait 5 seconds for the Enter to be pressed down
If (ErrorLevel == 0)
{
Send, {Enter}
sleep 200
Send, {F2}
}
else
{
traytip, , timeout ; Enter was not pressed down in 5 seconds
}
return
Basically, it appears you're trying to assign different tasks to the same hotkey and due to this being done seperately ahk is selecting one of the tasks and running with that task and only that task. If loops can be used within hotkeys, so I would suggest using this to rotate between the two expected outcomes. Please see example below:
temp:= 1
enter::
if(temp==1)
{
Send, {ENTER}
temp:=2
}
else if(temp==2)
{
Send, {F2}
temp:=1
}
return
1::
Temp:=1
return
2::
temp:=2
return
^x::ExitApp
I also added in hotkeys for 1/2 to allow you to manually decide the outcome rather than it being specifically assigned in the case of any issues.
Oh, and ctrl+x to close the macro.
You're trying to rebind the enter key twice.
Rebinding a key is like saying "When I press this key, do this:" - in this case it's under an #IfWinActive so it's more like "When this window is open and I press this key..."
When you break that down you have "When I press enter - press F2" as well as "When I press enter, press enter"
What you're wanting to achieve is make the rebind conditional - i.e. it only sends F2 under certain conditions.
It's hard to know how to help without more context. Is there any reason you can't use a different key combination? Like Ctrl + Shift + Enter?
Something like:
+^Enter::send, {F2}
This is my slightly modified version of kidmar's script from AHK forums.
The script should change Backspace key behaviour, i.e. when we press Backspace in Windows Explorer, it works like Alt-Up (we go up one level in files hierarchy).
For some reason it doesn't work. How it should be fixed?
FunBackspaceExplorer()
{
IfWinActive, ahk_class CabinetWClass
{
ControlGetFocus, focused, A
IfNotInString, focused, "Edit" ; Return true only if current control isn't an edit control
return 1
}
return 0
}
#If, FunBackspaceExplorer() ; Backspace hotkey exists only if all conditions are met
Backspace:: SendInput, !{Up}
#If
(There are another working solutions for this task, but I'm interseted in this one).
Your version works on my system, if I use:
#If, FunBackspaceExplorer() ; Backspace hotkey exists only if all conditions are met
Backspace::
SetKeyDelay 10,1000
SendEvent {Alt down}{Up down}{Alt Up}{Up Up}
return
#If
SetKeyDelay inserts a delay between a down event and up event for a send, or a delay after sending keys.
It does not work with SendInput.
I use this hotkey to close the current Window :
:*:xx::
Send, {Alt Down}{Sleep 100}{f4 Down}{Alt Up}{f4 Up}
return ;
How can the script be amended so that the characters xx are not sent to display but are still registered by autohotkeys ? In other words if focus is within open editor do not display the xx characters but still fire the commands associated with the xx keys.
You can't do it with a Hotstring but you would have have to use a Hotkey and check for a double key press. A regular key like x might not be the most useful as it will most likely always get in the way of your regular typing as you want to block the x being sent. An example with Ctrl:
~Ctrl::
KeyWait, Ctrl ; wait for Ctrl to be released
KeyWait, Ctrl, D T0.2 ; and pressed again within 0.2 seconds
if ErrorLevel ; timed-out (only a single press)
MsgBox single
else
MsgBox double
return
The above code comes from here http://www.autohotkey.com/board/topic/23224-resolved-catch-a-double-press-click/#entry150299 and you will also find an example (no 4) on the KeyWait doc http://ahkscript.org/docs/commands/KeyWait.htm
I wrote a simple script wich open the active joomla site administrator page in Firefox:
#a::
Send, !d
GetText(url)
StringGetPos, localHost, url, localhost
startPos := 7
if(localhost)
startPos := 17
StringGetPos, pos, url, /,,startPos
adminURL := SubStr(url,1,pos)
Send ^t%adminURL%/administrator{enter}
return
GetText(ByRef txt) ;copy the selected text to clipboard
{
BlockInput, on
prevClipboard = %clipboard%
clipboard =
Send, ^c
BlockInput, off
ClipWait, 2
txt = %clipboard%
txt:=RegExReplace(txt,"\x20{2,}"," ")
clipboard = %prevClipboard%
}
At first use (after reboot) the script do weird things:
logout
open command line
open Windows Explorer
It looks like the windows key is still in pressed state when I send the input.
After first use the script work properly.
I think something is wrong with the getText function.
I try a lot of modification, but doesn't work.
Can somebody help me?
Let the hotkey label wait until you have released each key:
#a::
KeyWait, LWin ; or RWin, as desired
KeyWait, a ; just to make sure nothing interferes
/*
do stuff!
*/
return
In contrast to #a UP::, this won't let a key press trickle through when releasing A first.