Toggle 3 keyboard layouts Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mjbatty
Posts: 19
Joined: 05 Nov 2020, 08:50

Toggle 3 keyboard layouts

Post by mjbatty » 29 Nov 2022, 10:50

Hi all, not been back on here for a while and only know the basics.

I have 3 physical keyboards of different sizes which means some commong keys are in different positions; I can change the key caps so some of the keys I want are in the same or similar physical position, but then need to remap the original keys.

I have the following to simply toggle one of the keyboards on/off as a test but it does not work; the next step would be some way to select (dynamically) different keyboards.

If anyone could help get this first toggle working it would be a great help.

Code: Select all

keychron = true
...
^!k::
keychron := !keychron
Return
...
#if (keychron)
	; Remap/swap page and home/end keys
	PgUp::send {Home}
	PgDn::send {End}
	Home::send {PgUp}
	End::send {PgDn}

	; Similar maps for Ctrl, Shift and Ctrl+Shift with page and home/end keys
#if

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

Re: Toggle 3 keyboard layouts  Topic is solved

Post by mikeyww » 29 Nov 2022, 11:32

Looks OK.

Code: Select all

keychron := True

^!k::
keychron := !keychron
MsgBox, 64, Keychron, %keychron%
Return

#If keychron
PgUp::Send x
#If
PS:
keychron = true
= is used to assign to literal strings.

Code: Select all

keychron := true
Explained: Var := expression

Next time, instead of
It does not work
actually say something about what happens, and what should happen instead.

The problem that you are having may relate to the part of your script that is not posted here.

mjbatty
Posts: 19
Joined: 05 Nov 2020, 08:50

Re: Toggle 3 keyboard layouts

Post by mjbatty » 29 Nov 2022, 11:36

Thanks @mikeyww , I tried that but still not working?

mjbatty
Posts: 19
Joined: 05 Nov 2020, 08:50

Re: Toggle 3 keyboard layouts

Post by mjbatty » 29 Nov 2022, 11:42

Sorry @mikeyww , I'll post the whole keychron section in case there is some interference.

When I say not working I mean the original unmapped keys are sent, for example the page up (now with a Home key cap) does page up instead of moving to the start of a line (in Word for example).

Code: Select all

#if keychron
	; Remap page and home/end keys
	PgUp::send {Home}
	PgDn::send {End}
	Home::send {PgUp}
	End::send {PgDn}

	; Move to start/end of buffer/doc
	^PgUp::send ^{Home}
	^PgDn::send ^{End}

	; Move to top of previous/next tab/screen/page
	^Home::send ^{PgUp}
	^End::send ^{PgDn}

	; Select from cursor to start/end of line
	+PgUp::send +{Home}
	+PgDn::send +{End}

	; Select from cursor to top of previous/next tab/screen/page
	+Home::send +{PgUp}
	+End::send +{PgDn}

	; Select from cursor to start/end of buffer/doc
	^+PgUp::send ^+{Home}
	^+PgDn::send ^+{End}

	; Not sure but remap for completeness
	^+Home::send ^+{PgUp}
	^+End::send ^+{PgDn}
#if
[Mod edit: [code][/code] tags added.]
Last edited by gregster on 29 Nov 2022, 11:44, edited 1 time in total.
Reason: Please use code tags. Thank you!

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

Re: Toggle 3 keyboard layouts

Post by mikeyww » 29 Nov 2022, 11:51

You script starts with the context active. When you trigger the hotkey, it becomes inactive. That's how you programmed it.

mjbatty
Posts: 19
Joined: 05 Nov 2020, 08:50

Re: Toggle 3 keyboard layouts

Post by mjbatty » 29 Nov 2022, 12:23

I thought I replied about 20 mins ago 🤔

To begin, my apologies; I am suffereing from Covid at the moment and my brain is not at it's best!

@mikeyww thank you, your replies got me in the right direction (and yes, keychron is the default).

I was checking it quickly in Word but for some reason Word was not picking up the changes after the toggle, however other programs are and it is working correctly now when I toggle on/off several times.

@gregster apologies, I thought I did use code tags - but will blame it on Covid!

I will post again when head is clearer about switching between 3 or more keyboards.

Thanks again all, much appreciated.

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

Re: Toggle 3 keyboard layouts

Post by mikeyww » 29 Nov 2022, 12:46

You could add a sound, tooltip, on-screen display, or other notification when you change keyboards. That may help to avoid some confusion.

mjbatty
Posts: 19
Joined: 05 Nov 2020, 08:50

Re: Toggle 3 keyboard layouts

Post by mjbatty » 29 Nov 2022, 13:05

All working now thanks @mikeyww , I'll accept your previous answer, appreciated.

Post Reply

Return to “Ask for Help (v1)”