How to double space as ctrl key? - autohotkey

I want the space key to work like Ctrl after 200 ms of being pressed. So, in theory it should work like this:
while space key is press down {
for first 200 ms {
if another key is pressed or space key released {
work like normal space
go no further
}
}
after first 200 ms {
if another key <Key> is pressed {
Send Ctrl+Key
}
}
}
Is it possible with AutoHotKey?

At least part of this is possible with AutoHotkey, the below fulfills everything except 'if another key is pressed'. It might be possible if you made every key a hotkey and then used A_PriorHotkey. Or perhaps there is another way I haven't thought of.
$Space::
KeyWait, Space, T2
if(ErrorLevel) {
Input, SingleKey, L1, {LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{CapsLock}{NumLock}{PrintScreen}{Pause}
Send {Ctrl down}%SingleKey%{Ctrl up}
} else {
Send {Space}
}
return
I took the input part from here.

Related

How to detect fn key press in Swift?

I want to detect when the user presses the fn key and do some tasks. I tried the below but it doesn't work:
if event.keyCode == kVK_Function {
print("fn key pressed")
}
I have similar code for other keys like left bracket, right bracket, slash, alphabets, and numbers. For these, similar code, as shown above, works fine but it doesn't work for fn key. I think this is handled differently.
You need to check the NSEvent's modifierFlags:
if event.modifierFlags.contains(.function) {
print("fn key pressed")
}

how can i create an equivalent "$" effect on mouseclick events in AHK?

I'm trying to create an AHK script where the right mouse click is intercepted, similar to a $ call would work with a keyboard press. This is the code I've tried but the right click still is sent to the program.
$capslock::
send {u down}
var = 0
return
$capslock up::
send {u up}
var = 1
return
$rbutton::
if(var) {
;
} else
sendinput, {s}
return
Any help would be appreciated!

combining hotkeys

I'm trying to make an autoclicker in autohotkey but can't get it to work.
I have some knowledge about autohotkey but it is not very much:
<^LButton::
Loop
{
SetMouseDelay 0.001
Click
If(GetKeyState("LButton","P")=0)
Break
}
It works with <^LButton as hotkey, but not <^nLButton.
Therefore I need help with hotkey-combinations.
I get the errorcode:
Line Text: <^nLButtonSuspend
Error: This line does not contain a recognized action.
If you want to combinate Three keys as a Hotkey.
Click the Keys : [Ctrl] + [n] + [Lbutton] = Do a Action.
You can Try this:
example1.ahk
;#notrayicon
#SingleInstance force
^n::
GetKeyState, state, Lbutton
if state = D
{
Loop
{
send a
;SetMouseDelay 0.001
;Click
If(GetKeyState("LButton","P")=0)
Break
}
} else {
send b ;this codeline is only so that you can test it out in notepad. - you can remove this
}
Return
esc::exitapp
note : It is not perfect but the answer is close to your Question.

Autohotkey Return to regular function of Spacebar after mapping

i am trying to be able to toggle between different functions mapped to the spacebar
mapping spacebar isnt difficult, but how the hell do i get the "regular" function of spacebar back ?
Space::Space isnt working XD
BackSpace::tog()
tog()
{
static togstate = 0
if (togstate = 1)
{
ToolTip, Spacebar Normal
SetTimer, RemoveToolTip, 1500
Space::
togstate = 0
}
else
{
ToolTip, Spacebar Alternativ
SetTimer, RemoveToolTip, 1500
Space::
{
SetKeyDelay,5, 10
Send, 2345
}
return
togstate = 1
}
}
Ordinary hotkey bindings are more like declarations than commands or functions. So, they need to be on the global level.
You just need to use the Hotkey command, either inside or outside of functions.
Example:
Hotkey Space, funcA
Hotkey Space, funcB
Hotkey Space, Off
funcA() {
...
}
funcB() {
...
}

Autohotkey: Ctrl + 1 mapping

I want to remap mouse click to a button depend on a state of Numlock. If Numlock is 'ON' then I want the normal behavior else map to mouse click. The script I created below works fine but I have trouble remapping CTRL+1.
SHIFT+1 will result in '!' so it is simple to do but I don't know what's the behavior for CTRL+1 is. The current script has the dummy "Send, {^1}" but that is not the real behavior.
I appreciate any suggestion.
*The Keywait is for simulating holding the mouse button and the script is enable/disabled base on Numlock state.
$1::
if GetKeyState("NumLock","T")
Send, {1}
else
{
Click down,
KeyWait 1
Click up
}
Return
$+1::
if GetKeyState("NumLock","T")
Send, {!}
else
{
Click down,
KeyWait 1
Click up
}
Return
$^1::
if GetKeyState("NumLock","T")
Send, {^1}
else
{
Click down,
KeyWait 1
Click up
}
Return
The following should do what you've described, with some cleanup to the code itself. I also recommend reading up on the various Send modes, as SendInput is superior in just about every way possible.
$1::
if GetKeyState("NumLock","T")
SendInput, 1
else
{
Click down
KeyWait 1
Click up
}
Return
$+1::
if GetKeyState("NumLock","T")
SendInput, {!}
else
{
Click down
KeyWait 1
Click up
}
Return
$^1::
if GetKeyState("NumLock","T")
SendInput, ^1
else
{
Click down
KeyWait 1
Click up
}
Return