Mimic CTRL + SHIFT down

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ericlch168888
Posts: 7
Joined: 08 Aug 2022, 10:51

Mimic CTRL + SHIFT down

Post by ericlch168888 » 08 Aug 2022, 10:56

Hi

i am new to this autohotkey

I am trying to program the following

when the capslock is pressed down, it should mimic the CTRL and SHIFT down. when CAPSLOCK is UP, the CTRL and SHIFT should be up too

I tried the following but how to do the 2nd part i.e when capslock is up , CTRL and SHIFT is also up?

Code: Select all

CapsLock::
{
	Send {LCtrl Down}
	Send {LShift Down}

}
return
Last edited by BoBo on 08 Aug 2022, 14:06, edited 1 time in total.
Reason: Changed subject line from 'help' to 'Mimic CTRL + SHIFT down' to be more specific.

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Mimic CTRL + SHIFT down

Post by wetware05 » 08 Aug 2022, 14:25

Hi ericch168888, welcome.

See this address: https://www.autohotkey.com/docs/KeyList.htm#IME

CapsLock is a special key that communicates a state of the keyboard. Do you want the LCtrl and LShift keys to be released when CapsLock is not active?

ericlch168888
Posts: 7
Joined: 08 Aug 2022, 10:51

Re: Mimic CTRL + SHIFT down

Post by ericlch168888 » 08 Aug 2022, 16:56

Yes shift and ctrl be released when the caps key is released.

or can i assign any key e.g the ~ key(any key that is on left of keyboard) if i cant use the caps lock key?

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Mimic CTRL + SHIFT down

Post by wetware05 » 09 Aug 2022, 05:06

Why a third key? What if pressing Ctrl causes Shift to be pressed at the same time, and releasing Ctrl releases Shift? We cannot help you without clearly knowing what you want (and for what situation, if possible). Do you want to hold Ctrl+Shift keys for a long time for some use? If it is for some game, it is better to make this request in the game forum. There they have more experience on these issues.

jrachr
Posts: 531
Joined: 01 Mar 2021, 17:33

Re: Mimic CTRL + SHIFT down

Post by jrachr » 09 Aug 2022, 07:27

@ wetware5
Good Day.This has me intrigued.While I would not use this for games having the option to use control and shift together as a hotkey would benefit me to use my current control hotkeys for something else. IE I currently have Capslock remapped as control. And I have a script where I use control(Capslock) and d for volume down and control(Capslock) and f for volume up. If i could remap capslock or any key for that matter to control and shift and then just add a letter to complete the hotkey that would be ideal.Can this be done? IE Remap capslock to control & shift to send ^+ when pressed down and up when released? Tk's

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Mimic CTRL + SHIFT down

Post by wetware05 » 10 Aug 2022, 17:41

I created this script from other forums. See if it's what you need:

(Be very careful when using this script. It is not a good idea to use Capslock as a keyboard shortcut.)

Code: Select all

OnExit, ExitSub
~^+CapsLock::
~CapsLock::

RepeatKey := !RepeatKey
If RepeatKey
	SetTimer, SendTheKey, 100	; The "100" here is the number of milliseconds between repeats.
Else
	{
	SetTimer, SendTheKey, Off
	Send, {LShift Up}
	Send, {LCtrl Up}
	}
Return

SendTheKey:
Send, {LShift Down}
Send, {LCtrl Down}
Return

^+F10::
Msgbox, Keys are being pressed Ctrl+Shift
Return

^Esc::
^+Esc::
Send, {LShift Up}
Send, {LCtrl Up}
ExitApp
Return

ExitSub:
 Send, {LShift Up}
 Send, {LCtrl Up}
 ExitApp
 
;-----Function---------
AutoRepeat(Key, Duration:=0)
{
	End := A_TickCount + Duration
	While, A_TickCount < End
	{
		SendInput, {%Key% DownR}
		Sleep, 30
	}
	SendInput, {%Key% Up}
}
Attention! Always exit the program having disabled the keys to be pressed, otherwise it will interfere with other programs. To be safe better exit the script with the keyboard shortcut Ctrl+Esc. The commented out code should work, but it doesn't. Expert question: how to make sure that when exiting a script no key is left pressed?

One of the problems with this script proposal is that if you are pressing Ctrl+Shift, then the CapsLock keystroke is different (it will always be Ctrl+Shift+CapsLock, so you have to put two keyboard shortcuts). I have put the shortcut ^+F10 to verify that the condition is met, that you are holding down Ctrl+Shift, because pressing only F10 already has to meet the condition.

Another problem is that the caps lock light may blink. Hitting again deactivates it. At least on my system.

Post Reply

Return to “Ask for Help (v1)”