Author Topic: Autohotkey Problem: How to swap keys  (Read 4384 times)

0 Members and 1 Guest are viewing this topic.

Offline berserkfan

  • Thread Starter
  • Posts: 2135
  • Location: Not CONUS Not CONUS Not CONUS Not CONUS
  • changing diapers is more fun than model f assembly
Autohotkey Problem: How to swap keys
« on: Tue, 20 August 2013, 00:44:50 »
Hello Everyone!

I have recently been tinkering with my 122-key Lexmark. My latest attempt is an exercise with moving the function 1-12 key row up and swapping it with f13-24. My aim is to make the original f1-12 serve as various hotkeys and macros, while the f13-24 will take the place of f1-12.

That way I can get easily accessed hotkeys, while retaining the normal f1-12 (at a further distance) in case I want to use them.

Here is an example of the code that is giving me problems:

f1:: Send !po
Return
Sc05b:: Send {f1}
Return

Sc05b is the code that the key standing in the place of f13 sends.
!po alternate-p-o runs a shortcut in my MS word.

I am successful with making the original f1 run my shortcut.
But the new f1 aka old f13/ scancode 05b is not cooperating. According to autohotkey, it returns f1 and alt, p, o.

I tried recoding as
Sc05b:: f1
And it returns f and 1.

I tried recoding as
*Sc05b:: Send {f1}
Return
And it returns F1 and alt, p, o.

How can I make sc05b return only f1? (Applies to the rest of the function 13-24 row.)
Most of the modding can be done on your own once you break through the psychological barriers.

Offline laffindude

  • Posts: 1521
  • ( ̽ ¬ ˳¬)
Re: Autohotkey Problem: How to swap keys
« Reply #1 on: Tue, 20 August 2013, 09:51:39 »
Are you using a terminal M or a terminal emulator and how are you connecting it?

Offline alaricljs

  • I be WOT'ing all day...
  • ** Moderator Emeritus
  • Posts: 3715
  • Location: NE US
Re: Autohotkey Problem: How to swap keys
« Reply #2 on: Tue, 20 August 2013, 10:04:15 »
You have not remapped anything.  You have told AHK to send F1 when F13 is pressed and to send !po when F1 is pressed.  So you now have F13 being caught and sending F1, and that F1 signal being caught and sending !po.  Then the  F1 key is still sending F1 and being caught and turned into !po.

Code: [Select]
f1::Sc05b

Sc05b::f1

Sc05b:: Send !po
Return
Filco w/ Imsto thick PBT
Ducky 1087XM PCB+Plate, w/ Matias "Quiet Click" spring-swapped w/ XM Greens

Offline berserkfan

  • Thread Starter
  • Posts: 2135
  • Location: Not CONUS Not CONUS Not CONUS Not CONUS
  • changing diapers is more fun than model f assembly
Re: Autohotkey Problem: How to swap keys
« Reply #3 on: Tue, 20 August 2013, 11:23:49 »
terminal emulator; connecting via the original sdl-ps2 connector.


Are you using a terminal M or a terminal emulator and how are you connecting it?
Most of the modding can be done on your own once you break through the psychological barriers.

Offline berserkfan

  • Thread Starter
  • Posts: 2135
  • Location: Not CONUS Not CONUS Not CONUS Not CONUS
  • changing diapers is more fun than model f assembly
Re: Autohotkey Problem: How to swap keys
« Reply #4 on: Tue, 20 August 2013, 11:25:21 »
I'm afraid you are right.

What can I do to tweak my code then? I want to transpose the entire F1-12 row up to F13-24, while I want the original F1-12 rows to be my own macros and hotkeys that I can reach more easily while typing.

You have not remapped anything.  You have told AHK to send F1 when F13 is pressed and to send !po when F1 is pressed.  So you now have F13 being caught and sending F1, and that F1 signal being caught and sending !po.  Then the  F1 key is still sending F1 and being caught and turned into !po.

Code: [Select]
f1::Sc05b

Sc05b::f1

Sc05b:: Send !po
Return
Most of the modding can be done on your own once you break through the psychological barriers.

Offline laffindude

  • Posts: 1521
  • ( ̽ ¬ ˳¬)
Re: Autohotkey Problem: How to swap keys
« Reply #5 on: Tue, 20 August 2013, 11:59:32 »
bind Sc05b to the scancode of F1, not "F1" since it is calling it as a function.

Offline alaricljs

  • I be WOT'ing all day...
  • ** Moderator Emeritus
  • Posts: 3715
  • Location: NE US
Re: Autohotkey Problem: How to swap keys
« Reply #6 on: Tue, 20 August 2013, 12:46:23 »
The code I posted is "proper" AHK remapping... did you try it out?  It swaps F1 and F13 and then assigns the !po to the key previously known as F1.

laffindude may be correct w/ the F1 scancode, but I've never had to do that with AHK.    All you should need is matching pairs of remaps like the one I showed which will swap your low Fs with your high Fs.  Then you write hotkeys against the NEW mapping.

My recommendation is start with just remap pairs and test them.  If they work, swap the keycaps so you easily have it straight in your head.  After that write hotkeys against the keycaps *as labelled*.  So F1 gets the F13 keycap and you write a hotkey against F13.
« Last Edit: Tue, 20 August 2013, 12:48:28 by alaricljs »
Filco w/ Imsto thick PBT
Ducky 1087XM PCB+Plate, w/ Matias "Quiet Click" spring-swapped w/ XM Greens

Offline berserkfan

  • Thread Starter
  • Posts: 2135
  • Location: Not CONUS Not CONUS Not CONUS Not CONUS
  • changing diapers is more fun than model f assembly
Re: Autohotkey Problem: How to swap keys
« Reply #7 on: Tue, 20 August 2013, 13:15:30 »
Ah,...

Am I starting to understand something?

So there is a difference between a scancode and a 'name'? Didn't think about it earlier!

bind Sc05b to the scancode of F1, not "F1" since it is calling it as a function.
Most of the modding can be done on your own once you break through the psychological barriers.

Offline berserkfan

  • Thread Starter
  • Posts: 2135
  • Location: Not CONUS Not CONUS Not CONUS Not CONUS
  • changing diapers is more fun than model f assembly
Re: Autohotkey Problem: How to swap keys
« Reply #8 on: Tue, 20 August 2013, 13:50:04 »
Thanks for your help, alaric, but it really did not work. I'm also quite confused now. After all I was never much of a programmer to begin with. I have remapped keys successfully in the past, but never actually swapped them one vs one.


The code I posted is "proper" AHK remapping... did you try it out?  It swaps F1 and F13 and then assigns the !po to the key previously known as F1.

laffindude may be correct w/ the F1 scancode, but I've never had to do that with AHK.    All you should need is matching pairs of remaps like the one I showed which will swap your low Fs with your high Fs.  Then you write hotkeys against the NEW mapping.

My recommendation is start with just remap pairs and test them.  If they work, swap the keycaps so you easily have it straight in your head.  After that write hotkeys against the keycaps *as labelled*.  So F1 gets the F13 keycap and you write a hotkey against F13.
Most of the modding can be done on your own once you break through the psychological barriers.

Offline Daniel Beardsmore

  • Posts: 1874
  • Location: Hertfordshire, England
  • RIP
    • Boring twaddle
Re: Autohotkey Problem: How to swap keys
« Reply #9 on: Tue, 20 August 2013, 18:20:35 »
Couple of things to try, as a test:

1) Use a and b instead of F1 and Sc05b
2) Use a bog standard keyboard

I'm a bit tired, but alaricljs's code appears to work fine for me with a and b. The above test should rule out any oddities with scancodes and keyboard compatibility.

Also, be aware that key swapping in AutoHotkey is (or at least, was) broken in XP. The problems I had in XP didn't occur in Windows 7, and the above a/b swap works fine for me in Windows 8.
Bore Awards
Most Boring Person on the Planet – 2011 Winner

Offline berserkfan

  • Thread Starter
  • Posts: 2135
  • Location: Not CONUS Not CONUS Not CONUS Not CONUS
  • changing diapers is more fun than model f assembly
Re: Autohotkey Problem: How to swap keys
« Reply #10 on: Wed, 21 August 2013, 00:36:57 »
Hi Daniel

Thanks for your suggestions.

I tried the a and b swapping (the same example was given on ahk’s website). Plain a and b work, but f1 and sc05b or sc06b (f20) did not work.

In the meantime I have been working on a time format.

EG
::ttt::
FormatTime, Time,, yyyy-MM-dd
SendInput, %Time%
Return

Works fine when I use ttt (or b, or [, or anything that doesn’t belong to the function keys)
Doesn’t work when I try to use a function key, including sc05b, sc06b, etc in place of ttt.

My intention was to see if I can use a function key as a hotkey for inserting the date, but it doesn’t work also.

I’m thinking there are special things about the function keys that require different rules or something, but I don’t know autohotkey well enough to use them well.

Let me stress again that the f13-24 row work fine if I am simply mapping their scancodes to other keys. I've also checked with autohotkey's key logger which can recognize that these non-104key ANSI keys are being pressed.

eg sc06b::a returns a when that key is pressed.



Couple of things to try, as a test:

1) Use a and b instead of F1 and Sc05b
2) Use a bog standard keyboard

I'm a bit tired, but alaricljs's code appears to work fine for me with a and b. The above test should rule out any oddities with scancodes and keyboard compatibility.

Also, be aware that key swapping in AutoHotkey is (or at least, was) broken in XP. The problems I had in XP didn't occur in Windows 7, and the above a/b swap works fine for me in Windows 8.
Most of the modding can be done on your own once you break through the psychological barriers.

Offline laffindude

  • Posts: 1521
  • ( ̽ ¬ ˳¬)
Re: Autohotkey Problem: How to swap keys
« Reply #11 on: Wed, 21 August 2013, 03:08:45 »
Ah,...

Am I starting to understand something?

So there is a difference between a scancode and a 'name'? Didn't think about it earlier!

Ya. Key names can also be interpreted as a label. So you can invoke a key's function simply doing a "Gosub thatkey".

::xxx:: is hotstring. The xxx part only really work with characters and certain keys. http://www.autohotkey.com/docs/Hotstrings.htm Read the remarks section.

There are a few ways you can write what you want, and the easiest way to just to copy the %time% variable to clipboard and send ctrl+v to paste it. You do want to write it as a function, such as "Sc05b:: [your function stuff]".



PS, how did you bind the F13? I don't have a terminal board to test, but binding F1 to F3 as a test works for me with scancodes>>
Code: [Select]
Sc03B::send {Sc03D}
F3::A
It rebinds F1 as F3, and does not invoke F3's function.

Offline berserkfan

  • Thread Starter
  • Posts: 2135
  • Location: Not CONUS Not CONUS Not CONUS Not CONUS
  • changing diapers is more fun than model f assembly
Re: Autohotkey Problem: How to swap keys
« Reply #12 on: Wed, 21 August 2013, 07:59:24 »
hey guys

sorry for giving you all trouble but somehow along the way I stumbled into the right solution.

The solution is to entirely eschew the use of names like f1, f12, f20 in favor of the scancodes. Remapping one scancode to another is the same as a::b
eg sc06b::sc058.

The code doesn't look so easy to understand anymore, but it works fine. Using f1, or send {f1}, doesn't work.
Most of the modding can be done on your own once you break through the psychological barriers.

Offline Daniel Beardsmore

  • Posts: 1874
  • Location: Hertfordshire, England
  • RIP
    • Boring twaddle
Re: Autohotkey Problem: How to swap keys
« Reply #13 on: Thu, 22 August 2013, 18:10:43 »
AutoHotkey is incredibly useful, but it's also probably a violation of the Eight Amendment or the Geneva Convention or something … you couldn't create something that twisted no matter how hard you tried.
Bore Awards
Most Boring Person on the Planet – 2011 Winner