How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Sandro_spb
Posts: 23
Joined: 05 Oct 2021, 15:22

How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by Sandro_spb » 05 May 2023, 18:44

Hi, when I press F2 on my keyboard it sends: {CTRL down}{a down}{CTRL up}{a up} . How to remap this sequence as F2? Without harming Ctrl+A usage

Here this sequence:

Code: Select all

F2:

A2  01D	 	d	9.39	LControl 
41  01E	 	d	0.00	a              	
A2  01D	 	u	0.09	LControl       	
41  01E	 	u	0.00	a 

Ctrl+A:
             	
A2  01D	 	d	2.67	LControl       	
41  01E	 	d	0.41	a              	
41  01E	 	u	0.14	a              	
A2  01D	 	u	0.26	LControl

User avatar
boiler
Posts: 17393
Joined: 21 Dec 2014, 02:44

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by boiler » 05 May 2023, 19:29

Isn’t this the same as your old thread on the same topic? Are you now looking to do the same in AHK v2?

Sandro_spb
Posts: 23
Joined: 05 Oct 2021, 15:22

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by Sandro_spb » 06 May 2023, 03:03

boiler wrote:
05 May 2023, 19:29
Isn’t this the same as your old thread on the same topic? Are you now looking to do the same in AHK v2?
Yes, I try to make it on V2. How it's possible? On V1 some times Ctrl+A doesn't work properly.

User avatar
boiler
Posts: 17393
Joined: 21 Dec 2014, 02:44

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by boiler » 06 May 2023, 06:44

Show what you tried in v2.

Sandro_spb
Posts: 23
Joined: 05 Oct 2021, 15:22

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by Sandro_spb » 06 May 2023, 07:46

@boiler,

Code: Select all

F3::KeyHistory

^F3::ListHotkeys


Myflag :=0

$*a::{
    if (GetKeyState("Ctrl", "P") and Myflag) {
        Send "{F2}"
        Myflag := 0
    }
    Send "{a}"
    return
}
$*Ctrl::{
    Myflag := 1
    Send "{Ctrl}"
    return
}

This code, gives me eroor:


Image

User avatar
boiler
Posts: 17393
Joined: 21 Dec 2014, 02:44

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by boiler » 06 May 2023, 07:58

Put the following line as the first line in each of your functions:

Code: Select all

global Myflag

Sandro_spb
Posts: 23
Joined: 05 Oct 2021, 15:22

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by Sandro_spb » 06 May 2023, 14:50

@boiler, I added, but still same error:

Code: Select all

F3::KeyHistory

^F3::ListHotkeys

global Myflag


Myflag :=0

$*a::{
    if (GetKeyState("Ctrl", "P") and Myflag) {
        Send "{F2}"
        Myflag := 0
    }
    Send "{a}"
    return
}
$*Ctrl::{
    Myflag := 1
    Send "{Ctrl}"
    return
}

Image

User avatar
boiler
Posts: 17393
Joined: 21 Dec 2014, 02:44

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by boiler » 06 May 2023, 15:30

Read my last post again. Declaring global outside the functions doesn't do anything in v2.

Alpha_Moose
Posts: 23
Joined: 06 May 2023, 07:15

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by Alpha_Moose » 06 May 2023, 15:32

@Sandro_spb
Pretty sure if you are evaluating an If statement you need to provide an expression against 'MyFlag'. What are you evaluating MyFlag for exactly? If it passes the If statement and you set it right back to 0 why not just omit the MyFlag from your if statement entirely?

Try this if you are just making sure MyFlag equates to or less than 0

Code: Select all

if (GetKeyState("Ctrl", "P") && Myflag <= 0)

User avatar
boiler
Posts: 17393
Joined: 21 Dec 2014, 02:44

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by boiler » 06 May 2023, 15:35

@Alpha_Moose - There already is an expression that is evaluating Myflag. Where it says and MyFlag, that part will be evaluated as True when it equals 1 and false when it equals 0. No change is necessary regarding that.

Alpha_Moose
Posts: 23
Joined: 06 May 2023, 07:15

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by Alpha_Moose » 06 May 2023, 15:41

@boiler
Ah that would make sense. You're definitely correct about the global variable thing - AFAIK V2 doesn't support dynamic vars which would explain why MyFlag is coming up as null.

User avatar
boiler
Posts: 17393
Joined: 21 Dec 2014, 02:44

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by boiler » 06 May 2023, 16:11

I'm not sure how you're trying to display it, but it should display as 0 or 1 once the scope is set correctly as I described.

Sandro_spb
Posts: 23
Joined: 05 Oct 2021, 15:22

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by Sandro_spb » 06 May 2023, 16:43

@boiler, thank you! Now there is no errors, BUT remap is not working. When i press F2 it works as "a".

Could you please advice - how it's better tor remap F2 buttona working as Ctrl+a -> to work as F2?

Code: Select all

F3::KeyHistory

^F3::ListHotkeys

global Myflag:=0


Myflag :=0


$*a::{

 global
 if (GetKeyState("Ctrl", "P") and Myflag) {
        Send "{F2}"
        Myflag := 0
    }
    Send "{a}"
    return
}

$*Ctrl::{
    global
    Myflag := 1
    Send "{Ctrl}"
    return
}
[Mod edit: Removed spoiler-tags with [code][/code] tags.]

User avatar
boiler
Posts: 17393
Joined: 21 Dec 2014, 02:44

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by boiler » 06 May 2023, 17:47

I'm not really following what you're trying to accomplish, and these types of remapping scripts don't really appeal to me. Hopefully someone else can help from this point.

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by mikeyww » 06 May 2023, 18:57

Code: Select all

#Requires AutoHotkey v2.0
F2::Send '{Ctrl down}{a down}{Ctrl up}{a up}'

Sandro_spb
Posts: 23
Joined: 05 Oct 2021, 15:22

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by Sandro_spb » 07 May 2023, 17:58

@mikeyww, thank you for helping me! I try to do opposite thing. when I press F2 on my keyboard it works as shortcut Ctral+A , but I need to remap it back to F2

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: How to remap: {CTRL down}{a down}{CTRL up}{a up} :: F2

Post by mikeyww » 07 May 2023, 18:34

1. What should happen when you press Ctrl+A?

2. What should happen when you press F2?

Post Reply

Return to “Ask for Help (v2)”