GUI: piano keyboard

Get help with using AutoHotkey and its commands and hotkeys
User avatar
SpeedMaster
Posts: 204
Joined: 12 Nov 2016, 16:09

Re: GUI: piano keyboard

14 Apr 2018, 16:45

jeeswg wrote:- Does anybody have any good AHK links for a piano keyboard GUI? Thanks.

hello,
I think this one is the most advanced so far:
Klavier Hero 2010 by Bentschi :ugeek:
topic: http://ahkscript.org/germans/forums/vie ... php?t=6803





:!: You can resize the gui by dragging the corner

Cheers
Last edited by SpeedMaster on 19 Apr 2018, 07:39, edited 2 times in total.
User avatar
jeeswg
Posts: 4782
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GUI: piano keyboard

17 Apr 2018, 01:03

- Thanks SpeedMaster, this is really nice. I had searched the forums for piano scripts and hadn't found this one.
- The keys appear to be set up for a German keyboard, so I've provided a script below for people to adjust the keyboard keys as appropriate. Replace the HotkeysLine1 and HotkeysLine2 lines in the script.

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


- The script is working, but the keyboard is only displaying for me in AutoHotkey Basic/AutoHotkey v1.1 ANSI. Here's a fix for AutoHotkey v1.1 x32 Unicode, you need to replace 'str' with 'astr' in lines that use GetProcAddress.

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

User avatar
SpeedMaster
Posts: 204
Joined: 12 Nov 2016, 16:09

Re: GUI: piano keyboard

17 Apr 2018, 09:24

jeeswg wrote:I've provided a script below to adjust the keyboard keys as appropriate
Here's a fix for AutoHotkey v1.1 x32 Unicode, you need to replace 'str' with 'astr' in lines that use GetProcAddress.

Thanks for the fix. :D
I added a new link for x32 version and US keyboard (see the previous link) :thumbup:
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: GUI: piano keyboard

17 Apr 2018, 17:34

I've modded the script to use scancodes instead of virtual keys, which should allow its usage regardless of the keyboard layout, and also changed some data types for attempted compatibility with x64 systems (not tested). Anybody interested? I could post it tomorrow if this sudden cold doesn't kill me by then.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
jeeswg
Posts: 4782
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GUI: piano keyboard

17 Apr 2018, 18:02

That would be interesting Drugwash, thanks.
I've tried to correct the script to make it work in AHK v1.1 x64 also.
See TIPS FOR CONVERTING OLD SCRIPTS, here [note: includes AHK v1.0 to AHK v1.1 advice]:
AHK v1 to AHK v2 conversion tips/changes summary - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=37&t=36787
note: the code is set up for a UK keyboard, but there are other variants you can uncomment (search for 'HotkeysLine')

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

Last edited by jeeswg on 18 Apr 2018, 04:00, edited 1 time in total.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: GUI: piano keyboard

18 Apr 2018, 02:00

Thanks but I'm not interested at all in AHK v2. Syntax remains as it was with only minor changes/improvements. It might even be compatible with AHK 1.0 and Win9x (although that would require more work), but unfortunately can't test that now.
I haven't checked all OpenGL calls either, they're just too many and I wasn't feeling well last night. Maybe these days I'll do it.
Labels were also changed to English since not everybody knows German.
Only tested in AHK 1.1 Unicode x86 under XP. If anyone tests this under x64, please provide feedback.

You have a bug in your version, one of the VKs is duplicated in HotkeysLine1 which makes one note unplayable.

There is one drawback I noticed: when system is under more or less heavy load, timing becomes inaccurate, script lags. This may not happen on modern multiprocessor computers but I don't own such machine to test on.

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

I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
jeeswg
Posts: 4782
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GUI: piano keyboard

18 Apr 2018, 02:58

- Ah, the name of my link was a bit misleading, it has general conversion advice for all versions, not just for AHK v2. All of the code I've posted on this thread is for AHK v1.1.
- SpeedMaster changed the script to run on a some keyboard or other, I've used that code. My code from earlier, should make it possible to set up the keys for whatever keyboard you have.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: GUI: piano keyboard

18 Apr 2018, 03:14

Indeed the link name is misleading. And I'm too lazy to actually check it out. :)
Usage of scancodes should eliminate these layout problems, they can even be switched on the fly. The only problem I see is for 101 keyboards that would miss the leftmost note (below A).
There still are minor things to fix regarding some OpenGL calls, I'm working on that at the moment.
Have you tested it yet, at least in x86?
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
jeeswg
Posts: 4782
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GUI: piano keyboard

18 Apr 2018, 03:24

- I have some code to automate correcting the OpenGL calls, I just to need make an adjustment to support Str/AStr/WStr, not just Ptr, then I'll update my code above.
- My script above is working on AHK v1.1 x64 and x32, Unicode and ANSI.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: GUI: piano keyboard

18 Apr 2018, 03:37

I like to do corections manually (what a blasphemy to say that in an automation tool's forum board! :lol: ), if only to understand better how the script works. ;)

Have you tested my version in x64? I don't have such machine here.
Yours is still using a few ANSI calls regardless of the AHK encoding. I put them all on an automated switch (that AW variable that should've been in AHK by default long ago together with A_CharSize).

[EDIT]
Please check line 387, both parameters should be pointers:
DllCall("opengl32.dll\wglMakeCurrent", Ptr, 0, Ptr, 0) First is HDC, secoond is HGLRC.
Line 417, parameter is also pointer:
hRC := DllCall("opengl32.dll\wglCreateContext", Ptr, hDC)
Same as line 387 above, in line 418:
DllCall("opengl32.dll\wglMakeCurrent", Ptr, hDC, Ptr, hRC)
Line 612 and 613 need a couple of pointers each and maybe use the AW approach:

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

DllCall("opengl32.dll\wglUseFontOutlinesA", Ptr, hDC, UInt, Asc("A"), UInt, Asc("Z")-Asc("A")+1, UInt, FontOut, Float, 0, Float, 0.2, Int, 0, Ptr, &gmf)
DllCall("opengl32.dll\wglUseFontOutlinesA", Ptr, hDC, UInt, Asc("A"), UInt, Asc("Z")-Asc("A")+1, UInt, FontIn, Float, 0, Float, 0.2, Int, 1, Ptr, 0)


That's about it, at a quick look.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
jeeswg
Posts: 4782
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GUI: piano keyboard

18 Apr 2018, 04:09

- @Drugwash: I tested your script, and unfortunately it was not working on AHK v1.1 x64. [EDIT:] The script worked apart from the GUI keyboard, the subwindow opened but the keyboard didn't show.
- I basically prepared a list of dll functions and parameter types, and automatically converted the DllCall lines (and checked using WinMerge). I also went over NumGet/NumPut/VarSetCapacity (and DllCall) lines manually.
- You are so right re. the variables, even now there should be two variables that give W or A, and 2 or 1, and it's the sort of thing I would like backported to 'AHK v1.0.50'.
- Btw it's not always necessary to convert an 'A' function to a 'W' function, I just left lines 612 and 613 as 'A'.
- All of the corrections that you mentioned were handled correctly by my converter. The updated script is available above. Cheers.
Last edited by jeeswg on 18 Apr 2018, 14:50, edited 1 time in total.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: GUI: piano keyboard

18 Apr 2018, 06:59

How strange. What exactly do you mean by "it was not working"?
- was the MIDI device detected properly (name appears in the top list)?
- does keyboard appear with characters drawn on them?
- does it play any sound at all, on any key or mouse click?
- are you using an USB keyboard? Maybe scancodes are different.
Ah, just noticed I didn't have the correct return data types for the GL procedures. Maybe that was it.

A few years ago I had started updating AHK 1.0.48.05 but got too greedy and messed up, then got sidetracked by other things and lost interest. It had AW, A_CharSize, A_PtrSize and other BIVs implemented in AHK 1.1.

The wglUseFontOutlines() API builds the characters that are to be displayed on keys. Currently it only works with capital A to Z latin characters, moreso when only the ANSI version of it is used, which is a limitation because there are so many different keyboards in this world and not all of them have native latin characters on the caps, or at least not all of them are in the A-Z range. I intend to perform an on-the-fly conversion from scancode to actual (Unicode) characters and add an option for the user to select their actual layout as it physically appears on the keyboard, so the correct characters would be displayed in the virtual keyboard. Well, at least it's a nice idea. :)

Please try this one, hopefully it'll work in x64:
(fixed thanks to jeeswg)

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

Last edited by Drugwash on 18 Apr 2018, 16:41, edited 1 time in total.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
jeeswg
Posts: 4782
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GUI: piano keyboard

18 Apr 2018, 14:55

- With your new script, the keys play, but as before the GUI keyboard subwindow displays, but the keyboard doesn't show, before it just wasn't drawn, now it appears as a black rectangle. Also, I had to remove the 'updates' function.
- Well done on your tweaks to AutoHotkey Basic.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: GUI: piano keyboard

18 Apr 2018, 15:24

Ouch, updates() is necessary for AW and A_CharSize, I'm so used to it here that I forgot to replace it with the declarations as in previous version. If you do that locally maybe it'll start working correctly.
(my head is messed up by a sudden cold, sorry for these issues)
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
jeeswg
Posts: 4782
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GUI: piano keyboard

18 Apr 2018, 15:36

So use this?
A_CharSize := 1
AW := "A"
The keyboard GUI was still blank.
And the Device drop-down list was showing all Chinese characters.
And pressing keys to play notes stopped working.
Try comparing older scripts with my newer script using WinMerge.
We need to avoid ending up like KeypressOSD with updates twice a day.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: GUI: piano keyboard

18 Apr 2018, 15:47

AW := A_IsUnicode ? "W" : "A", A_CharSize := A_IsUnicode ? 2 : 1 ; these can be found in some newer scripts of mine, in updates.ahk
It's in previous version above. What you put above would only work for ANSI AHK.

I looked through your code and the visible diferences were in some data types, Int vs UInt.
If I had an x64 machine it probably would've been fixed already; since I don't, I'm shooting in the dark.

off-topic:
Keypress has opened a whole can of worms, problems are deeper that they may appear and it's not (only) the code, it's the OS itself, maybe even MSKLC or any tools that have been used to create certain layouts that do not behave like the older ones and so on. The only problem is with dead keys and their combination, but that's enough to mess things up badly.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
jeeswg
Posts: 4782
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GUI: piano keyboard

18 Apr 2018, 16:27

I tried:
AW := A_IsUnicode ? "W" : "A"
A_CharSize := A_IsUnicode ? 2 : 1
And got the same results as before, black where the keyboard is, but keys working.

I fixed the line starting 'glNewList := DllCall', and your script worked.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: GUI: piano keyboard

18 Apr 2018, 16:35

OK, thank you. I need a new pair of eyes because the glasses don't help anymore.
Glad it finally works. Cheers!
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
SpeedMaster
Posts: 204
Joined: 12 Nov 2016, 16:09

Re: GUI: piano keyboard

19 Apr 2018, 07:47

Many thanks for all the improvements you have made. :bravo:
The US keyboard was falsely generated by my french AZERTY keyboard (I forgot to switch to US keys :facepalm: ). :?
In fact it seems that both US and UK keyboards are generating exactly the same code. (not tested with real US keyboard) :)
I updated my previous download post with the 2 versions. :thumbup:



Cheers
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: GUI: piano keyboard

19 Apr 2018, 09:22

Merci beaucoup. :)
Hopefully the scancode system will fit any possible layout without the need for tweaking the code. All that remains is to have the user choose the proper layout so the characters displayed on the keys would fit those on the physical keyboard (regardless of the software layout chosen for the system/application).
Unfortunately I spent all day on a wild goose chase today, otherwise I might have improved it more. But there's still time. ;)
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.

Return to “Ask For Help”

Who is online

Users browsing this forum: TomT and 60 guests