make Eject key act as Delete

Get help with using AutoHotkey and its commands and hotkeys
Mark N
Posts: 5
Joined: 19 Jan 2018, 18:56

make Eject key act as Delete

22 Jan 2018, 17:54

I am using a Bluetooth Apple Wireless Magic Keyboard 2 with a Lenovo Yoga Book running Windows 10 Home. The keyboard works fine but I want to make the Eject key act as a Delete key, just as in Alvin Poh's article at
https://www.alvinpoh.com/how-to-remap-k ... -keyboard/
I have tried several of the newest versions of AutoHotKey 1.0.* and 1.1.* but all give this same error when running any .ahk script file:

"Error: Cannot jump from inside a function to outside" with an arrow pointing to the next "Goto, CleanUp" statement in the code and a final message that says, "The program will exit."

AutohotkeyRemoteControl.dll is in the same folder as all the AutoHotKey.exe files which are in either the "Program Files" or "Program Files (x86)" folder depending on the AutoHotKey version. I have tried changing (EditUsage =1 and EditUsagePage =12) to (EditUsage =2 and EditUsagePage =1) or to (EditUsage =6 and EditUsagePage =1) in the .ahk files but the error is always the same. Does anyone have any other suggestions besides trying all 150 versions of AutoHotKey? Thank you.
[code=autohotkey file=Untitled.ahk][/code]
User avatar
divanebaba
Posts: 626
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: make Eject key act as Delete

22 Jan 2018, 23:07

Hello.
Alvin Poh hasn't remap his eject-key, so it is a bit difficult for me, to find out the correct name for the eject-key.
But before starting support please show me (or us) your script. Without a look inside, it is impossible to support.
BTW: Alvins code should be better, when $-prefix is used.

Code: [Select all] [Download] GeSHi © Codebox Plus

$LAlt::LWin
$LWin::LAlt
$RAlt::End
$RWin::Home
After a look into your script, perhaps you have to do some maybe unknown steps described here. You have to translate it or learn german language. :mrgreen:
Mark N wrote:... Does anyone have any other suggestions besides trying all 150 versions of AutoHotKey? ...
Use latest AHK-Version supporting UNICODE (version 1.1.27.07 is up to date)

[Starklichtbirne IQ >> 250!!] Dank deutscher Lehrerempfehlung, nur Süperdepp und Hartz4-Bezieher, statt Abitürient und Einkommensbezieher.
[Strong light bulb IQ >> 250!!] Thanks to german teacher's recommendation, willful and welfare recipient, instead of high school graduate and moneymaker.

Entering high school for foreign children is not prohibited in GERMANY, it's only made nearly impossible by government.
Virtually the only way - visiting high school abroad.
User avatar
evilC
Posts: 4095
Joined: 27 Feb 2014, 12:30

Re: make Eject key act as Delete

23 Jan 2018, 05:56

As far as I am aware, windows has no concept of an "Eject" key.
From my searching, it also does not appear to be defined as a Mac key.

That probably does not mean it is un-readable though, you just need to find it's ScanCode.
See here: https://autohotkey.com/docs/KeyList.htm#Special_keys
User avatar
evilC
Posts: 4095
Joined: 27 Feb 2014, 12:30

Re: make Eject key act as Delete

23 Jan 2018, 06:00

Update: It seems someone has looked at this before, and the Eject key is not exposed as a ScanCode maybe?
https://autohotkey.com/board/topic/1278 ... eject-key/

It seems that it can be read via AHKHID, or there is a DLL to allow you to remap it to a media key or something.
just me
Posts: 5342
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: make Eject key act as Delete

23 Jan 2018, 06:29

Apparently, the scripts have been created using a rather out-dated version of AHK. Try to replace Goto, CleanUp with Gosub, CleanUp.
Mark N
Posts: 5
Joined: 19 Jan 2018, 18:56

Re: make Eject key act as Delete

23 Jan 2018, 13:08

divanebaba wrote:Hello.
Alvin Poh hasn't remap his eject-key, so it is a bit difficult for me, to find out the correct name for the eject-key.
But before starting support please show me (or us) your script. Without a look inside, it is impossible to support.
BTW: Alvins code should be better, when $-prefix is used.

Code: [Select all] [Download] GeSHi © Codebox Plus

$LAlt::LWin
$LWin::LAlt
$RAlt::End
$RWin::Home
After a look into your script, perhaps you have to do some maybe unknown steps described here. You have to translate it or learn german language. :mrgreen:
Mark N wrote:... Does anyone have any other suggestions besides trying all 150 versions of AutoHotKey? ...
Use latest AHK-Version supporting UNICODE (version 1.1.27.07 is up to date)


Hello divanebaba,
Thank you for your posting.
I am using AutoHotKey 1.1.27.7 so the problem is not that I have an old version of AHK. Rather, I think the problem is that the scripts are too old.
The scripts are just the ones posted on Alvin Poh's page at this link: https://www.alvinpoh.com/downloads/AutoHotKeys.zip
which unzip into 6 files having these names:
INSTRUCTIONS.txt, AutohotkeyRemoteControl.dll, AutoHotKeyRemoteControlDLL.ahk, "Keyboard Media Keys - detect.ahk", "Keyboard Media Keys Actions.ahk" and "Keyboard Media Keys.ahk"
I assume the posting is quite old since all the replies are from 2010 and 2011. I have tried adding the "$" prefix characters to the lines you mentioned which are in the "Keyboard Media Keys.ahk" file. I have also tried the other suggestion from the posting by "just me" to replace "Goto, CleanUp" with "Gosub, CleanUp" but the error is always the same. I do not understand ANYTHING about these scripts, how they are supposed to work or even where they are supposed to be located. Since Alvin got them to work with an Apple keyboard that is just an earlier version of the one I am using, I believe that the only problem is the the AutoHotKey language has evolved to be different from when the scripts were written and it is porbably a matter of a few statements that need to have their syntax changed to make them current. I was hoping someone might be able to see that by just looking at the scripts.
User avatar
evilC
Posts: 4095
Joined: 27 Feb 2014, 12:30

Re: make Eject key act as Delete

23 Jan 2018, 13:29

GOTO is not allowed inside a function, but GOSUB is.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



So if you are getting the same "Cannot jump from inside a function to outside" when using a GoSub, then something is seriously wrong.
Are you 100% sure you are changing ALL GoTos to GoSubs? This is a pre-execution check, so just changing the first GoTo that it would hit is not going to make the script load.
User avatar
evilC
Posts: 4095
Joined: 27 Feb 2014, 12:30

Re: make Eject key act as Delete

23 Jan 2018, 13:35

By the way, another fix is this:

Where you had MyLabel:, change it to to a function:

Code: [Select all] [Download] GeSHi © Codebox Plus

MyLabel(){
global ; Forces assume-global mode, makes a function work like a label
}


Then just replace Goto, MyLabel with MyLabel()

Also, whether replacing a GoTo with a GoSub or with a function call, be aware that a GoTo would NOT return to the line after, so if you had code like:

Code: [Select all] [Download] GeSHi © Codebox Plus

if (someCondition){
Goto, MyLabel
}
DoSomethingElse()


Then you would need to add a return statement (or similar) to make the code halt execution after returning:

Code: [Select all] [Download] GeSHi © Codebox Plus

if (someCondition){
Gosub, MyLabel
return
}
DoSomethingElse()
Mark N
Posts: 5
Joined: 19 Jan 2018, 18:56

Re: make Eject key act as Delete

23 Jan 2018, 16:02

Thanks evilC.
I replaced all GOTOs with GOSUBs and added the "$" before the four key names as divanebaba's post suggested. Now the error message has changed to: RegisterDevice failed. Errorcode: -3

In the INSTRUCTIONS.txt file it says,"If you can't get it to recognise the USB media keys, you will probably need to find out the EditUsage and EditUsagePage values for your device using AutoHotKeyRemoteControlDLL.ahk and then change the references at the beginning in both the other ahk files."

Right now EditUsage =1 and EditUsagePage =12. How to I use AutoHotKeyRemoteControlDLL.ahk to tell if those values are correct?
If I just run AutoHotKeyRemoteControlDLL.ahk I get this error message: GetDeviceCount fehlgeschlagen. Errorcode: -3
I don't know what he means by "using AutoHotKeyRemoteControlDLL.ahk" to find out the correct values for EditUsage and EditUsagePage. Do you have any idea what he is talking about?

I should also mention that the file "Keyboard Media Keys Actions.ahk" consists of the following short bit of code which suggests to me that 4854 is the code for the Media-Eject key that I would like to assign to be a Delete key. Does that seem correct to you?

Key_Action_Check:
IfEqual, Vals, 4854, Gosub 4854
Return

4854: ; Eject
send {delete}
Return
just me
Posts: 5342
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: make Eject key act as Delete

24 Jan 2018, 04:47

Alvin Poh's scripts seem to be based on DLLCall: Support for Human Interface devices by Micha. A new version AHKHID - An AHK implementation of the HID functions without a Dll has been created by TheGood in 2009. You might want to use this version.
User avatar
divanebaba
Posts: 626
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: make Eject key act as Delete

24 Jan 2018, 14:19

I recommend to find the scan code of the eject-key.
Look for instructions on this page in help-file.

Try to find scan code - it is recommended and easiest way.

If there is no scan code for the eject-key, it will be bit difficult.

[Starklichtbirne IQ >> 250!!] Dank deutscher Lehrerempfehlung, nur Süperdepp und Hartz4-Bezieher, statt Abitürient und Einkommensbezieher.
[Strong light bulb IQ >> 250!!] Thanks to german teacher's recommendation, willful and welfare recipient, instead of high school graduate and moneymaker.

Entering high school for foreign children is not prohibited in GERMANY, it's only made nearly impossible by government.
Virtually the only way - visiting high school abroad.
Mark N
Posts: 5
Joined: 19 Jan 2018, 18:56

Re: make Eject key act as Delete

31 Jan 2018, 17:50

Hello "just me",
I tried AHK 1.1.25.02 on the "Keyboard Media Keys.ahk" file and it gives the same error message as all the other versions I have tried, that is: "RegisterDevice failed. Errorcode: -3"
I suppose that error might mean that AHK can't recognize the keyboard. Or maybe not. Is there a list of error messages somewhere that might help decipher the error message?
Why does AHK give the same error code (-3) for a different error? For example, when I run AHK on the script file "AutoHotKeyRemoteControlDLL.ahk" it gives this error: "GetDeviceCount fehlgeschlagen. Errorcode: -3" which seems like a different error but it has the same error code number. That's not very helpful.
just me
Posts: 5342
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: make Eject key act as Delete

01 Feb 2018, 05:17

The error codes seem to be reported after DllCall(). -3 means
The specified DllFile could not be accessed or loaded. If no explicit path was specified for DllFile, the file must exist in the system's PATH or A_WorkingDir. This error might also occur if the user lacks permission to access the file, or if AutoHotkey is 32-bit and the DLL is 64-bit or vice versa.
in this case. I'm pretty sure that the Dll is 32-bit. Are you running AHK 64-bit?
Mark N
Posts: 5
Joined: 19 Jan 2018, 18:56

Re: make Eject key act as Delete

06 Feb 2018, 12:18

Hello "just me",
The Yoga Book that I want to use with the the Apple Magic Keyhoard 2 is 64-bit. All the versions of AHK that I downloaded are from this page:
https://www.autohotkey.com/download/
When I install an AHK version (for example, AHK 1.1.25.02) I get four different .exe files in C:\Program Files\AutoHotKey\ named: AutoHotKey.exe, AutoHotKeyA32.exe, AutoHotKeyU32.exe and AutoHotKeyU64.exe I have assumed that AutoHotKeyU64.exe is the one I should run since the computer is 64-bit. Is that the correct AHK and if not which is the correct one to run?

I have tried dragging and droping a .ahk script file such as AutoHotKeyRemoteControlDLL.ahk onto all four of the above .exe. file and they all give the same error: "GetDeviceCount fehlgeschlagen. Errorcode: -3", so what does that mean?

The only .dll file I have is called AutoHotKeyRemoteControl.dll and I have no idea whether it is 32-bit or 64-bit. I tried doing a Properties on it but it doesn't specify. The .dll file came from the original page by Alvin Poh here:
https://www.alvinpoh.com/how-to-remap-k ... -keyboard/
and was in the .zip file mentioned on and downloaded from the link on his page at: https://www.alvinpoh.com/downloads/AutoHotKeys.zip
Again, I have no idea whether it is 32-bit or 64-bit or how to tell which it is. Do you know how I can tell?

The .dll file AutoHotKeyRemoteControl.dll is in the same folder as the .ahk files, namely: C:\Program Files\AutoHotKey\AutoHotKeys\
Is that "in the system's PATH or A_WorkingDir"? I don't know what those two things mean. Can you please tell me the path to the directory that the .dll file should be located in so I can put a copy of it there?

It would be so much easier if there was a tutorial page somewhere where all the conditions that need to be satisfied for a script to run were listed.
just me
Posts: 5342
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: make Eject key act as Delete

07 Feb 2018, 04:56

Because the AHK scripts are clearly written for AHK 1.0 (32-bit) I'm pretty sure that the Dll is 32-bit. So you must use a 32-bit AHK to test it. Why don't you want to try
just me wrote:AHKHID - An AHK implementation of the HID functions
IMO it's much better documented and doesn't need an external Dll?
Guest

Re: make Eject key act as Delete

08 Feb 2018, 17:29

Hello "just me",

The reason why I don't want to try AHKHID is because I have already tried it and it seems to do nothing. I downloaded AHKHID.ahk, example_1.ahk, example_2.ahk and example_3.ahk from https://autohotkey.com/board/topic/3801 ... functions/ and put them in the same folder as the AutoHotKey .exe files. I have AutoHotKey 1.1.27.07 installed in C:/Program Files/AutoHotKey/ which means there are 4 different .exe files (AutoHotKey.ex., AutoHotKeyA32.exe, AutoHotKeyU32.exe and AutoHotKeyU64.exe) in that folder. I have yet to determine which one I should be running so I have tried running AHKHID.ahk with all of them and the result is the same with all of them: nothing happens. When I run any of the three example_x.ahk files I get the same error message: Error: Call to nonexistent function. Specifically: AHKHID_UseConstants()

I am not asking how to do something that is terribly complicated. I just want to make one key (the Media-Eject key) on a common keyboard (a Bluetooth wireless Apple Magic Keyboard 2) send the code for (Forward) Delete in Windows 10 running on a current model computer (a Lenovo Yoga Book). The original post by Alvin Poh that I started from (https://www.alvinpoh.com/how-to-remap-k ... -keyboard/) had already done the exact key remapping that I want for the previous model of the wireless Apple Keyboard. The problem is that AutoHotKey has changed so much since then that his script no longer works. Why is it that nobody on this site will reply with anything more than a hint as to how to solve a problem that has already been solved, maybe even multiple times? I'm guessing the steps necessary could easily be stated in 1-2-3 order if only somone were willing to do it.
just me
Posts: 5342
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: make Eject key act as Delete

09 Feb 2018, 04:00

Guest wrote:I am not asking how to do something that is terribly complicated.
No, you're 'only' asking how to run a skript written for AHK 1.0.39.00 on Win XP about 13+ years ago and shipped with a user-created external Dll file. ;)

Well, try to
  1. Reinstall AutHotkey by running the AutoHotkey_..._setup.exe.
    Choose Modify.
    Choose ANSI 32-bit
  2. Start the AHK script you need by double-click (it runs the script if you did not change the defaults).

Alternative:
  1. Uninstall AutHotkey by running the AutoHotkey_..._setup.exe.
  2. Download and install AutoHotkey104805_Install.exe.
  3. Start the AHK script you need by double-click (it runs the script if you did not change the defaults).
Good luck!

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 31 guests