I am currently using AutoHotKey to simulate the Happy Hacking Keyboard Pro 2 keys mapping on a Topre Realforce 89s.

The script I created is available on github.

I've used the Japanese key "muhenkan" (SC07B) to simulate the Fn key, and added all the Fn combination key mappings as in the two examples below:

SC07B & SC002::send,{Blind}{F1} ; Fn + 1 -> F1
SC07B & SC01A::send,{Blind}{Up} ; Fn + [ -> Up

Being located on the left and right side of the Space key, I additionally want to use "muhenkan" and "henkan" (SC079) as Enter and Backspace.

Remapping "henkan" to Backspace is easily done with:


Regarding "muhenkan", which is used as the Fn switch key, I mapped it to the Enter key with the following line:


It seems there is no conflict with it being used as both Fn and Enter:

  • when combined with another key, it doesn't output Enter
  • when no other key is combined, it outputs Enter after being released

There are times when I may first press that Fn key with the intent of combining it with another key, and eventually give up on that intent by releasing the Fn key.

The problem is that by releasing the key, it outputs Enter, which is not ideal.

I would like to improve this by configuring that Fn key so that when released, it only outputs Enter if the two following conditions are met:

  • not other key was pressed between the duration the Fn key was pressed and released
  • the duration between press/release (DOWN/UP) was less than a given value (ex.: 500ms)

Is there a simple way to modify my AutoHotKey configuration to continue using the SC07B as a switch key (Fn) and also map it to Enter with the earlier conditions?

The fact that I define key combinations seems to make the mapping to Enter work on key release, which is what I want, but it also means that I cannot use KeyWait and check for timeout, as I believe the commands will only start after key release (which makes no sense then).

A_TimeSincePriorHotkey is also not usable as it doesn't reflect the time spent between the current hotkey being pressed down and released.

  • While I will not post an answer as I can not figure out your first condition, you can use a combination of A_TickCount and Keywait to determine how long a key was pressed. – Elliot DeNolf Jun 4 '13 at 16:15
  • I'm going to edit and reformulate my question. It's as simple as: I want to remap a key to being both usable as an "Enter" when pressed and released in less than 500ms, and usable as a switch to create other mappings (ex. WASD arrow keys), to simulate the same behavior as the Fn key of some keyboards – killy971 Jun 5 '13 at 0:02
  • I see that you are trying to get access to the "normal" F1...F12 keys. On many systems, the BIOS is set such that you need the Fn key to get the "normal" F1...F12 keys. If this is your underlying problem, I suggest to look into your BIOS setting and switch the Fn key behaviour "back" to normal. This way, you don't need to play around with simulating the Fn key behaviour in ahk. – Robert Ilbrink Jun 5 '13 at 14:12

This is how you can use A_TickCount and KeyWait to determine how long a key was pressed:

LCtrl:: ;hotkey has 3 different functions based on press duration
    keyDown := A_TickCount
    Keywait LCtrl
    If ((A_TickCount-keyDown) < 300)
        Send {Enter}
    If ((A_TickCount-keyDown) > 300) and ((A_TickCount-keyDown) < 600)
        Send {Left}
    If ((A_TickCount-keyDown) > 600)
        Send {Right}

However, this does NOT allow you to use the key in combination (ie. Ctrl+a).

In order to accomplish this task, you must use While GetKeyState() similar to below:

    keyDown := A_TickCount
    While GetKeyState("RCtrl", "P")
        Send {Ctrl Down}
    duration := A_TickCount - keyDown
    Send {Ctrl Up}
    if duration < 300
        Send {Enter}

This will allow you to still perform key combinations like Ctrl+a, etc. Let me know if this answer works for you.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.