Autohotkey: Repeating keypress with key modifier held down - keyboard-shortcuts

How to rebind a key chord with Ctrl so that it repeats on multiple presses, while Ctrl is held down?
Example: I'm expertimenting with binding Ctrl+Space to Backspace.
^Space::Send {BackSpace}
When I now press Ctrl+Space correctly Backspace is sent and deletes the last character. I want now to keep Ctrl down and delete further characters with multiple Space strokes.

The trick is to use SendInput and release Ctrl:
^Space::sendinput {Ctrl up}{BackSpace}

Related

autohotkey: Cancel RButton user input after LButton pressed

In an fps I am trying to setup a hotkey such that when I am holding Lbutton (leftmouse), primary fire of a gun, and then tap RButton the LButton ceases and RButton commences. Ingame with no script, for other weapons, I get the desired result automatically. That is: I'm holding LButton, but if I also hold RButton 'after', the LButton ceases and the RButton's burst fire does its thing. However a different scoped weapon, with no script, freezes up when the above is done.
So I'm looking to, as soon as RButton is pressed, cease all user input of LButton until RButton's hotkey finishes.
~RButton
;Blockinput Mouse ;Send/Sendmouse
Send, {Click Left}{Click Right}{Click Left}
;BlockInput off
return
You can think of the Rbutton script as for a scoped rifle. Click Left activates scope, Click right fires it. Currently the desired behaviour only works when I completely remove my hand from LButton and then press RButton....I am also able to get ~LButton & ~RButton:: to work but that only covers the case when they r both first pressed at the exact same time, I want to cover the instance where LButton is pressed and held before RButton.
Ive tried applying blockinput, like seen above, had the UAC workaround to get it working, blocks certain things but doesnt seem to block any heldkeys when it is proc'd like the lbutton unless I'm missing something. If there was a "Freeze user input of LButton as soon as RButton procs, until RButton's script finishes" that would solve the problem I would think. I tried adding sleep delays, but they dont seem to help. The issue seems to be that LButton, when held, continues to proc when RButton first activates.
I used the below while holding LButton, and the sound DOES proc, so this must be possible to script.
*RButton::
Soundbeep
return
EDIT:
;code here works but only with that 100 sleep where i have to remove my hand from pressing the lbutton within 100ms of pressing rbutton.
*RButton::
GetKeyState, state, lbutton, p
if (state = "D")
{
soundbeep
send {Click Left Up}
sleep 100
;i need to actually disable the previous keypresses from it
}
Send, {Click Right}{Click Left}{Click Right}
return
From what I understood from your question, you don't really need to block user mouse input so much as Sending a Left MouseUp command if the Left mouse button was held down. I was having difficulty understanding what the end goal you were looking for was, but I wrote this based on what I was able to understand:
#SingleInstance Force
*RButton::
Soundbeep
If (getKeyState( "lbutton", "p" )){
Click, Left, Up
Send, {Click Left}{Click Right}{Click Left}
} else {
Send, {Click Left}{Click Right}{Click Left}
}
return
esc::ExitApp
UPDATE:
Based on the clarification from the comments of the question, this should work. Understood functionality: If the right mouse button is clicked while the left mouse button is held down, release the LMB, but do not suppress the RMB input.
*~RButton::
If (getKeyState( "lbutton", "p" ))
Click, Left, Up
return
UPDATE 2:
Now releasing the LMB before the RMB is pressed. I have a feeling that whatever game that you are playing will not be able to detect zero-tick switches between keystates, so I included a Sleep function that you can fine-tune/ remove as needed.
*RButton::
If (getKeyState( "lbutton", "p" )){
Click, Left, Up
Sleep 100
}
Click, Right, Down
KeyWait RButton
Click, Right, Up
return

Use SendKeys to send Alt combinations to enter special characters

I want to send an Alt combination to another window within a on-screen keyboard.
With combination I mean when you hold down Alt and enter a number or hexadecimal(registry key has to be set for hex) combination:
ALT down, Add press, 2 press, 5 press, 1 press, ALT up
I tried
SendKeys.SendWait("%{ADD}251") but it's Alt+Add 2 5 1
SendKeys.SendWait("%{ADD}%2%5%1") but it's Alt+Add Alt+2 Alt+5 Alt+1
SendKeys.SendWait("%({ADD}251)") but it's Alt and then the other keys pressed simultaneously
Ref to MSDN
Any suggestions for a solution with SendKeys or other classes?
[Edit]
Solution:
Example for CharCode (Element of enum Source): ʊ = &H28A
Dim CharCodeUnicodeStr As String = Hex(CInt([Enum].Parse(GetType(Source), CharStr))).ToString
SendKeys.SendWait("%{ADD}%" & ChrW(Convert.ToInt32(CharCodeUnicodeStr, 16)))
Put the keys within parentheses to indicate that ALT should be held down while pressing the others.
SendKeys.SendWait("%({ADD}251)")
Have you tried
SendKeys.SendWait("%{ADD}%" & ChrW(&H251))
This will convert your hexa code into a char. Then if you have control over the other application you can revert this char back to a number...

Disable Fn+F4 with AutoHotKey using time

I want to use AutoHotKey to disable Alt+F4 when they are pressed within 0.05 seconds of each other. Otherwise, I'd like it to work as normal.
Explanation:
My Lenovo Yoga 2 Pro has alternate functions for the function keys.
For example: "F3" is mapped to volume+, "F4" is mapped to "close active window"
There are two modes:
Old-school mode: F3 just acts as F3, and you must hold Fn+F3 key to activate volume+
New-school mode: Pressing F3 activates volume+, and Fn+F3 will do the normal F3.
In either mode, I run the risk of closing my active window when I go to use volume+ because they are too close, which is very problematic. Note that AutoHotKey cannot detect the Fn key, thus I cannot use that to solve my issue.
The image below shows the AutoHotKey Key History tool. In New-school mode, I typed "asdf" and then pressed "F4" which is "close active window". You can see this actually simulates ALT+F4, and there is a very short duration between ALT and F4...
I'm thinking that I could disable this "close active window" function by having AutoHotKey interrupt an ALT+F4 combo when there is less than 0.05 seconds between the two keys. Can this be done?
Edit:
In response to Blauhirn's code, here is the original, edited for a shorter wait duration, (from 50 to 10). It works most of the time, though 1/10 times the window is still cosed:
~alt::
hotkey, alt, off
hotkey, !F4, doNothing, on
sleep, 10
hotkey, !F4, doNothing, off
while(getKeyState("alt"))
sleep, 1
hotkey, alt, on
return
doNothing:
return
Here is a change I thought would fix my focus issue by sending a 2nd Alt when the "close active window" was detected:
doNothing:
send {LAlt}
return
However, the 2nd Alt is not sent. It IS sent when the delay is above 40ish, however I find that is way too long, and in turn it interferes with my manual use of Alt+F4.
Have you tried using simply
F4::return
? Maybe this will override the Lenovo action for F4
Other than that, here are the two approaches I can think of:
Disabling the ALT+F4 standard win hotkey by default. Adding a custom hotkey for a delayed F4
!F4:: ; by default:
doNothing: ; this is a label (see GoSub)
return ; == do nothing
~alt:: ; alt was pressed
sleep, 50 ; wait 50 milliseconds
if(!getKeyState("alt")) ; if alt is NOT pressed down anymore, exit
return
else ; (else is actually unnecessary here)
hotkey, !F4, close ; Add new AltF4-hotkey
return
close:
winclose, A ; close the Active window
return
~alt up:: ; alt is being released
hotkey, !F4, doNothing ; remove the new AltF4 hotkey and go back to custom standard behaviour: do nothing.
return
it still triggers Alt, which usually leaves me in the menu of the active window (File, Edit, View, etc), or if typing within a textarea (such is this), it will remove typing focus.
well yes. If you decide to keep the lenovo keys, I don't think there is a way to prevent it. As you suggested, sending ALT again should solve the problem
using Input, after ALT has been pressed. Input blocks user input for a configurable time, as long as the V option is used.
(3. disabling your Lenovo Yoga 2 Pro special keys. If you need the F3 function, you can do that in AutoHotkey e.g. using send {volume_up}

Assigning Keyboard shortcut other than ALT in Access

Just read about Assigning a Keyboard shortcut to a button in an Access. By using & in front of Caption of any control.
For example if want to assign Alt + N to a button, in Caption Property put &New
But this only assigns Alt.
Here are my Questions
& is to assign Alt, which is the symbol for Ctlr?
What about and Shift and Function Keys like F3?
Can these be assigned?
Is there any VBA code, or Property to add keyboard shortcuts?
For keys like F1, F2, F3 so on, you may code it directly in the VBA code, with a case/ or if else statement by checking for each vbKeyF1, vbKeyF2 etc with a KeyPress, KeyDown event trigger.
Take a look at these two references for using Autokey Macro as well.
Run an Access macro by using a keyboard shortcut.
Assigning Auto Keys for Aligning Controls.

How To Send Lower Caps String On VB.NET Using Sendkeys.send Whihe Shift key pressed

I want to sendkey "hello" using sendkeys command in vb.net but it sending "HELLO" because shift button is true.
Now How to send "hello" in lower case when shift key is true...
Try turning caps lock on using keybd_event in user32.dll. With caps lock on, you can "hold down" shift while "typing" lower case letters. Send Keys mimics using the keyboard, so you have to think about how you would do this with an actual keyboard.
See How do I toggle Caps Lock in VB.NET?