Author Topic: Autohotkey problem: make one key serve many purposes  (Read 5755 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: make one key serve many purposes
« on: Sat, 24 August 2013, 18:41:41 »
Hi

I have yet another three autohotkey problems

Problem 1: use one key for multiple purposes.

I don't ever use the original F10 function, so I've remapped it to ^w ctrl-w on one of my keyboards.

In the meantime I've gotten rid of tilde and ` since I rarely use them. (Remapped that key to something else) But once in a blue moon, maybe every few months, I find the need to use them.

So I'd like to use the F10 key for ~ ` also. I figured I could make alt and shift trigger layers for them.

My code doesn't work. Sc044 is the scancode for f10:

sc044::^w
!sc044::
Send {`}
Return
+sc044::~

Problem 2:
How to use a key combination and still retain the original key functions when key is pressed alone.
On another keyboard (this a buckling spring), I've been struggling to use the tilde key to trigger layers. but I want to use the tilde key alone also. I've read the fairly voluminous info at ahk's forum, but still don't get it. They say if I remap tilde to tilde, it will trigger when the key is released and no other key is pressed, but I haven't been able to do it.

`::Send {`}
return

` & 1::
CoordMode, Mouse, Screen
MouseClick, Left, 2, 700
CoordMode, Mouse, Relative
Return

I can get the mouse to move when I press tilde and 1. But when I press tilde alone, I don't get tilde.

Problem 3:
Am having difficulty remapping a key to work reliably and predictably as a windows key. Since I like to use a 122-key terminal, I generally want to remap one of the ten keys on the left side as a windows key. I keep finding problems, so if anyone has suggestions I'll be glad to hear them.

I tried different variants and didn't work. Now I must consult the geekhackforumpedia aka everybody's brains!

last but not least: SPECIAL THANKS TO DORKVADER FOR GIVING ME RELEGENDABLES! WITHOUT THESE GUYS I WON'T BE ABLE TO REMEMBER ALL THE MANY MACROS AND REMAPS I'M DOING WITH MY KEYBOARDS!
« Last Edit: Sat, 24 August 2013, 18:44:38 by berserkfan »
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: make one key serve many purposes
« Reply #1 on: Sat, 24 August 2013, 20:19:46 »
I've found a number of bugs and oddities with it, but since I also use a third-party keyboard layout (United Kingdom International) that does 80% of what I'm trying to do with AutoHotkey, I can never be sure that this isn't what's screwing things up.

For example, the keyboard layout makes ctrl+alt+8 = °. I wanted that to be • and to require shift in addition to give me °, i.e. like a Mac. The lines:

+^!8::° ; shift+ctrl+alt+8 = degrees
^!8::• ; ctrl+alt+8 = bullet

Every so often, I'd have to reverse the order of those lines to get it to work again. Then reverse them back a few months later. Then reverse them again … I am not aware of ever doing anything to trigger the need for the reversal (no new versions of anything, same keyboard etc).

ctrl+alt+c for copyright only works if I write it as follows:

^!c::SendInput {U+00A9} ; ctrl+alt+C = copyright

Just using a literal © inside the file causes the program to send garbage to the operating system (under Windows 8).

It's hard to tell when it's my mistake, and when the program is just broken. You never did confirm your OS — I know there are some serious bugs under XP, such as the inability to swap alt and Win. Matias use a compiled AHK script as their "driver" for the Tactile Pro to swap Win and alt, and it causes alt to jam when pressing alt+tab. This bug is gone under Windows 7 (never tried it in 8); under XP I just had to get used to mentally remapping the keys when using the TP.
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: make one key serve many purposes
« Reply #2 on: Sat, 24 August 2013, 23:38:50 »
my OS is Windows7 Home 64 bit.

I am extremely unlikely to change to another OS for years, so everything will be in the same OS. I hate paying extra money for zero improvements, not to mention more bugs and oddities everytime Miscosoft produces some new piece of crap.

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: make one key serve many purposes
« Reply #3 on: Sun, 25 August 2013, 07:28:33 »
Problem 1:

You can express problem 1 as simply this:

+F10::~
!F10::Send {SC029}
F10::^w

a) ` behaves oddly unless you express it as a scancode
b) Send is still required in the ! (alt) instance, as otherwise the computer thinks alt is still held, and you get a ding; you cannot write !F10::SC029

Problem 2:

See problem 1. You just hit on a particular key that AHK really struggles with.

Problem 3:

I cannot reproduce this. I can turn F11 into the windows key as follows:

F11::LWin

This opens the start screen, and it handles Win+E (Explorer), Win+L (lock) and Win+R (Run dialog) just fine. You'd need to describe your exact problems.

Note that AutoHotkey DOES NOT WORK when a high integrity process window is frontmost. Open Task Manager in Windows 8, and all input customisation software is effectively suspended (bypassed) until you switch to another window. F11 won't open the Start menu/screen, for example. The only way to get around this is to start your input customisation software from a scheduled task that runs during logon with process elevation enabled, so that it gets the privilege to manipulate the event system for high integrity processes. If you run as a non-admin user, I don't know how well this works either. Massive crackdown on security, probably to prevent keyloggers and what not.

Replicating the Windows key is therefore something of a headache.
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: make one key serve many purposes
« Reply #4 on: Sun, 25 August 2013, 12:08:41 »
Thanks a lot, Daniel. I’m going to try that out later tonight!

I think tilde is treated in a very unique way. Unfortunately, I like messing with remapping tilde precisely because I don’t use it much and it is right there for me to press (unlike the function row which is further away).

Thanks for the explanation for Windows key. Yes, I can use F11 reliably as a windows key if I’m only using it to open the start menu, or native-windows settings like Win-E. I used to do mappings like this:
#t:: run some macro
#y:: run another macro
#r:: do a certain thing
And what I found was that a remapped windows key sometimes works fine, sometimes returns weird results. Since I would use two keyboards connected to the computer, I would then check how a native windows key behaved, and the native key combo eg #r worked fine.
Sometimes the remapped windows key would return nothing, sometimes it would return my macro, and sometimes it would return a native windows function eg the Win+R function in your example. Since I can’t pin down what was wrong, eventually I abandoned my attempt to use the Windows key to trigger another layer. It works reliably only on native windows keys eg on my Cherry keyboards. When I use it on a Model M or F (ie when I remap a non-native key) it’s not reliable at all.


Problem 1:

You can express problem 1 as simply this:

+F10::~
!F10::Send {SC029}
F10::^w

a) ` behaves oddly unless you express it as a scancode
b) Send is still required in the ! (alt) instance, as otherwise the computer thinks alt is still held, and you get a ding; you cannot write !F10::SC029

Problem 2:

See problem 1. You just hit on a particular key that AHK really struggles with.

Problem 3:

I cannot reproduce this. I can turn F11 into the windows key as follows:

F11::LWin

This opens the start screen, and it handles Win+E (Explorer), Win+L (lock) and Win+R (Run dialog) just fine. You'd need to describe your exact problems.

Note that AutoHotkey DOES NOT WORK when a high integrity process window is frontmost. Open Task Manager in Windows 8, and all input customisation software is effectively suspended (bypassed) until you switch to another window. F11 won't open the Start menu/screen, for example. The only way to get around this is to start your input customisation software from a scheduled task that runs during logon with process elevation enabled, so that it gets the privilege to manipulate the event system for high integrity processes. If you run as a non-admin user, I don't know how well this works either. Massive crackdown on security, probably to prevent keyloggers and what not.

Replicating the Windows key is therefore something of a headache.
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: make one key serve many purposes
« Reply #5 on: Sun, 25 August 2013, 12:34:06 »
Sounds like a case for trial and error and studying the documentation for the myriad alternative ways of achieving the same thing, which is all I did to solve the ` problem — just break down the problem into each step and try each one until I found what wasn't working, which turned out to be that alt was being mistakenly held; then I just needed to get ` working with Send, which (for me anyway¹) releases alt first. I am not sure whose fault it is that this ended up being so absurdly complicated, but sadly, it is.

For example, if I write this:

#Q::Run, "cmd.exe"
F11::LWin

Then F11 becomes LWin, but F11+Q opens cmd followed by the start screen. Using & causes the basic binding to stop working altogether. The problem in part is that the Windows key is incorrectly designed to behave as two different types of key, and Autohotkey syntax doesn't accommodate this absurdity natively. (Actually, with my normal AHK script closed, the above mapping for F11+Q stops working at all.)

There may be ways to deal with keyup and keydown directly that might help (e.g. F11 keydown followed by Q). Another option suggested in the manual is using something like KeyTweak to remap the scancode at the Registry level, so the whole OS literally reads (say) F11 as LWin. This will be 100% reliable, but you also won't be able to turn it on and off.

¹ I was using right-click → New → AutoHotkey script for your tests, which inserts "SendMode Input"; oddly, my main script lacks this, so it will be running in SendMode Event. Constructions of the form a::b run in SendMode Blind, which doesn't release modifiers first.
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: make one key serve many purposes
« Reply #6 on: Mon, 26 August 2013, 04:23:33 »
Actually I have run into a fresh problem.

On the left side of my terminal, I have mapped pg up and pg down as well so that I can navigate with either hand.

plain old vanila page up and down work fine. But when I try to combine them with CTRL (as in CTRL page up, which scrolls between your tabs in google chrome) they don't work. Whether left or right control, both don't work on the remapped pg up or pg down.

Here's an example of what I mean:

Sc074::Send {sc049}
return
Sc075:: Send {PgDn}
Return
Both these keys are left terminal keys. I can use pgup and pgdn alone. But not ctrl-pgup or ctrl-pgdown.
I also cannot map sc074::sc049. AHK won't allow it for some reason

On the right side of the keyboard, I have
Sc151::sc049
Sc153::sc051
That's because the original terminal did not have pgup and pgdown in the standard positions, so I had to identify the scancodes sent and map them to pgup and down.
Ctrl-pgup and Ctrl-pgdn work with these remaps.

I wonder what is wrong and how to get around that.


Sounds like a case for trial and error and studying the documentation for the myriad alternative ways of achieving the same thing, which is all I did to solve the ` problem — just break down the problem into each step and try each one until I found what wasn't working, which turned out to be that alt was being mistakenly held; then I just needed to get ` working with Send, which (for me anyway¹) releases alt first. I am not sure whose fault it is that this ended up being so absurdly complicated, but sadly, it is.

For example, if I write this:

#Q::Run, "cmd.exe"
F11::LWin

Then F11 becomes LWin, but F11+Q opens cmd followed by the start screen. Using & causes the basic binding to stop working altogether. The problem in part is that the Windows key is incorrectly designed to behave as two different types of key, and Autohotkey syntax doesn't accommodate this absurdity natively. (Actually, with my normal AHK script closed, the above mapping for F11+Q stops working at all.)

There may be ways to deal with keyup and keydown directly that might help (e.g. F11 keydown followed by Q). Another option suggested in the manual is using something like KeyTweak to remap the scancode at the Registry level, so the whole OS literally reads (say) F11 as LWin. This will be 100% reliable, but you also won't be able to turn it on and off.

¹ I was using right-click → New → AutoHotkey script for your tests, which inserts "SendMode Input"; oddly, my main script lacks this, so it will be running in SendMode Event. Constructions of the form a::b run in SendMode Blind, which doesn't release modifiers first.
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: make one key serve many purposes
« Reply #7 on: Mon, 26 August 2013, 07:51:49 »
Use Send {Blind} instead of Send.

Send releases all the modifiers first unless {Blind} is prefixed to the Send parameters.
Bore Awards
Most Boring Person on the Planet – 2011 Winner

Offline Soarer

  • * Elevated Elder
  • Posts: 1918
  • Location: UK
Re: Autohotkey problem: make one key serve many purposes
« Reply #8 on: Mon, 26 August 2013, 08:22:31 »
There's 'UseHook on' as well, which might be useful. I can't remember because it's been a while since I tried to get AutoHotKey to do stuff like that (with Windows key etc).

It's far easier to do remappings in config for my converter - have your Teensies arrived yet?

Beyond that, it's up to you whether you do more in the converrter config, or more in AHK - using both together gives the best of both worlds. :D

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: make one key serve many purposes
« Reply #9 on: Mon, 26 August 2013, 10:12:35 »
Soarer! The master has visited my thread! OOOOO!

Thanks for all your advice. I’ve never used Hook or Blind, so that’ll be my next project.

Talking about remappings in config for your converter, I actually have a bit of problem with that. I remapped lshift on the Model F 84-key to Capslock, since there are two keys to the left of Z. (The key next to Z I remapped to lshift.)

For some reason, capslock always triggers whenever computer is starting up or waking up. Furthermore I have two keyboards hooked up, and the other keyboard’s LEDs don’t show capslock triggered until I type. I must press Capslock twice to remove it. It doesn’t matter what other keyboard that is – I’ve tried with a Deck Legend, a Model M-101,  Model M-122, a Cherry G80, or no other keyboard. Capslock always triggers and it can never be removed until I press the remapped key twice.

This condition holds true regardless of which key I have remapped capslock to. (EG function key, tilde key.) You see, on the Model F83, capslock is sitting precisely where I want my control key to be, so I always want to remap capslock and it is only a matter of where I relocate that naughty key.

I also would like to know how to program more complicated things on your converter. EG macros and key combos. Having no knowledge of programming, my only experience is with autohotkey. The syntax looks different from autohotkey’s. What kind of language am I supposed to use? What resources exist to teach me how to program your converter, beyond the very basic starter documents the Soarer comes with? Is there some programming language it uses that I can consult some other forum (wouldn’t want to keep bothering you on small noob issues)?
Most of the modding can be done on your own once you break through the psychological barriers.

Offline Soarer

  • * Elevated Elder
  • Posts: 1918
  • Location: UK
Re: Autohotkey problem: make one key serve many purposes
« Reply #10 on: Mon, 26 August 2013, 15:43:07 »
I can't reproduce the caps lock problem at all... tried loads of combinations of boot, sleep, different other keyboards attached, and it just works. Testing with a config of just:

Code: [Select]
remapblock
  CAPS_LOCK RCTRL
  LSHIFT CAPS_LOCK
  INTERNATIONAL_2 LSHIFT
endblock


The doc is basic, but does cover everything. What it doesn't go into is how you might use the features it provides (particularly macros) in any depth - it probably never will! The plan is add more example configs as time goes on, and index them, as a sort of 'cookbook'. Until then, there's been a few discussions about how to do certain things with macros in the threads, curiously, mostly on DT (from about page 5 or 6 on).

Get the latest docs (1.12) if you haven't already - the thread summary and search box is handy!

Macros are simpler than they look; you just need to get over the first hurdle :D

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: make one key serve many purposes
« Reply #11 on: Tue, 27 August 2013, 03:00:21 »
thanks a lot soarer! I will investigate this and try to learn what I can.

I may have a hook on the problem now.

I have a few damaged hammers/ contacts on my Model F left side. Some keys worked sporadically, others have never worked. Fohat.digs has advised me to open up and reseat the hammers.

Looking at my code, I realized that I have assigned F6 to CapsLock when F6 was working sporadically and didn't bother to remove the code after F6 totally stopped working.

BTW how do i assign a key to do nothing? I'm thinking that some of my Model F problems may be due to the damaged contacts, so I want certain keys to return nothing/ for computer to ignore if the damaged contacts return keystrokes.
Most of the modding can be done on your own once you break through the psychological barriers.

Offline Soarer

  • * Elevated Elder
  • Posts: 1918
  • Location: UK
Re: Autohotkey problem: make one key serve many purposes
« Reply #12 on: Tue, 27 August 2013, 04:31:12 »
Fohat's right, you know!

Until then, you can map to UNASSIGNED to prevent any output from bad keys.

Offline Daniel Beardsmore

  • Posts: 1874
  • Location: Hertfordshire, England
  • RIP
    • Boring twaddle
Re: Autohotkey problem: make one key serve many purposes
« Reply #13 on: Tue, 27 August 2013, 14:22:07 »
You know, I was very tempted to suggest that there must be something else wrong with your computer/keyboard/controller/adapter, considering how many issues you were having :)

If you want to map to nothing in AutoHotkey btw, apparently you just write: key::Return, e.g. LWin::Return (not that that blocks LWin in all programs — not a viable cure, so I have read).
Bore Awards
Most Boring Person on the Planet – 2011 Winner