I am trying to use autohotkey to add an artificial delay to a keypress. I am in a tiled room, with a mechanical keyboard, and a desktop microphone. I would like to add an artificial delay of approximately 1/10 of a second to my PTT key, so that others don't hear the audible CLICK when I press the key. I ended up binding the key to something else "numpad -" so that capslock could be the key I actually press. This is the script I ended up with.
Expected result: pressing capslock presses numpad- on a 0.1s delay, and then holds the key until I release capslock(and it should also unpress capslock on release)
Actual result: It works, but if I press and release it too quickly, it holds "numpad -" down and capslock down, and releases neither.
code:
#UseHook
*~Capslock::
sleep, 100
Send {NumpadSub Down}
sleep, 100
While GetKeyState("Capslock")
{
}
return
*~Capslock Up::
sleep, 300
Send {NumpadSub Up}
return
without the sleeps as is, the program opens the key, closes the key, and then re-opens.
UseHook
Answer:
*~Capslock::
sleep, 100
Send {NumpadSub Down}
keyWait, Capslock, U
sleep, 100
Send {NumpadSub Up}
return
Related
Suppose I'm reading a document in vi. When I reach the end of the screen and press the arrow down key, a new screen including the contents of the next line is printed in the terminal.
I wonder how this process is implemented.
Is vi process raise SIGTSTP and call signal handler to continue the process with new screen including next line?
Is ... process raise SIGTSTP and call signal handler ...
No.
The program first performs a tcsetattr() (which internally performs a special ioctl()) so the keyboard input is not handled line-wise but key-wise.
Then it prints out 25 lines.
Now it simply uses read() to wait for a key pressed.
If you press the DOWN key, one additional line is printed.
If you press the UP key (in the case of less), it is a bit more tricky; depending on the terminal used, some "escape sequence" (a special combination of bytes) is written to the screen using write(). This will cause the screen to be scrolled down. Then another "escape sequence" is written which places the cursor to the top left of the screen and one line of text is printed at the top of the screen.
When this is done, the program waits for the next key using read() ...
Signals are not involved.
My keyboard key/letter f is ruined and continuously presses the letter. I am using AutoHotKey to successully disable the letter, but I need an alternative hotkey to press the key. I have chosen to use CTRL+j as the hotkey to press the letter f. I tried this script but it does not seem to press the key:
f::return
^j::
Send f
return
I also tried this but it also does not work:
f::return
^j::
Send {f down}
return
How can I get the script to press f using the hotkey CTRL+j, while disabling the key f?
The $ modifier is going to solve this problem.
That modifier makes it so that your f::return hotkey wont affect keys that are sent from AHK.
So here's your finished script:
$f::return
^j::SendInput, f
Also switched over to SendInput due to it being the recommended faster and more reliable send mode.
I used the ASCII code for the letters in both uppercase and lowercase, and it also worked:
; disable the key 'f':
f::return
; press CTRL+j to press f:
^j::
Send {Asc 102}
return
; press CTRL+Shift+j to press F:
^+j::
Send {Asc 70}
return
I am getting a weird behavior while using pyautogui hotkey; where the special key used at times does "stick" and cause the subsequent text printed with pyautogui.typewrite() function to be printed incorrectly.
For example, this statement ran on OSX will cause shift to stick at random; causing the output to be printed capitalized.
pyautogui.hotkey("command", "shift", "f")
time.sleep(3)
pyautogui.typewrite("reference_file2.txt")
This will open the "recents" window in Finder, wait 3 seconds then will type a filename which should (or should not be) in the recents window. Sometimes the output of typewrite is printed like if Shift key was pressed.
So instead of
reference_file2.txt
You will see
REFERENCE_FILE#>TXT
which is exactly what you get if you type the original string with Shift key pressed.
Is this a bug in the hotkey function of pyautogui? Or am I supposed to do something to ensure that the keys pressed with hotkey is released, before moving on with the next statement? The documentation of pyautogui specify that the hotkey function does equal to a keypress and keyrelease sequence, so no action should be required, right?
I need to send a key press from the keyboard without manually/physically touching the keyboard.
I DON'T want to simulate key press events using SendKeys, or using AutoHotKey, etc. I need the signal to come from the keyboard's usb cable.
This script,
' Open notepad
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad", 9
' Give Notepad time to load
WScript.Sleep 500
'press some letters and capslock
WshShell.SendKeys "Hello World!"
WshShell.SendKeys "{CAPSLOCK}"
types the message, Hello World!, and 'presses' the capslock key causing the capslock led to light up (or turn off depending on the starting position). So I assume I am able to send a signal to the keyboard. How do I get the signal to be sent back?
Why do i get more than 1 (a few hundred) key hit on a single press while using GetAsyncKeyState. It prints a hundred of a same key while i just pressed it once.
Thanks,
GetAsyncKeyState tells you the state of the keyboard, whether a key is down/up, not whether it has been pressed since last call. If you call it in a loop, you will get "key is down" for as long as you keep the key down - and that loop executes a lot faster than you can move your fingers.
If you want keyboard events handle WM_KEYDOWN and WM_KEYUP.
If you want a global hotkey, use RegisterHotKey