[Script] KeypressOSD - Display key press on screen

Post your working scripts, libraries and tools
burque505
Posts: 177
Joined: 22 Jan 2017, 19:37

Re: [Script] KeypressOSD - Display key press on screen

31 Dec 2017, 19:23

Hi Marius, I didn't get very far, I'm afraid. Although everything works in Notepad, ª!"·$%&/()=?¿ in Spanish don't display on OSD. However, in the browser (i.e. here) everything seems to work in Spanish.
German: NO shifted characters appear in Notepad in the OSD. Here in the browser, a period followed by a space results in no capitalization of the next letter, but other caps appear. Also, ° does not appear in the OSD, but !"§$%&/()=? do.
Russian: In Notepad, shifted characters appear in the app, but not in the OSD. In the browser, shifted characters including Ё!"№;%:?**()_+ appear in the both the app and the browser.
Romanian: ”!@#$%^&*()_+ appear in browser and OSD. QWERTYUIOPĂΠlikewise. ASDFGHJKLȘȚ also. ZXCVBNM;:? also. €§[]\ do not appear in OSD. ' in browser bot not OSD. " likewise. Shifted letters sometimes, not always by any means, appear lower case in the OSD.
In Notepad, ”!@#$%^&*()_+ appear in app but not OSD. QWERTYUIOPĂÎÂ appear in Notepad but not in OSD. ASDFGHJKLȘȚ, likewise. ZXCVBNM;:?
That's all I had time for today, hope you are having a happy New Year!
Regards,
burque505
robodesign
Posts: 214
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

Re: [Script] KeypressOSD - Display key press on screen

31 Dec 2017, 20:45

Thank you very much for your feedback and patience.

Is this a regression? Or that's how it was?

Can you please tell me your pc specs?

Best regards, Marius.
User avatar
Drugwash
Posts: 400
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [Script] KeypressOSD - Display key press on screen

01 Jan 2018, 06:58

Unfortunately I can't download latest AHK_H using my current connection because it always times out. GitHub (and not only) are a bunch of bastards employing download timeout that makes us poor people unable to use their services.
Therefore I won't be able to provide feedback on current versions. Sorry.
robodesign
Posts: 214
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

Re: [Script] KeypressOSD - Display key press on screen

01 Jan 2018, 07:27

@drugwash: Please download it from: http://marius.sucan.ro/media/temp/ahkdl ... master.zip

I want your feedback as well ;-)
User avatar
Drugwash
Posts: 400
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [Script] KeypressOSD - Display key press on screen

01 Jan 2018, 09:42

Thank you, the download worked. :)

OSD does not display dead keys ˇ^˘°˛·´˝¨¸ at all, while in application they do appear.
Actually no AltGr-composed keys are displayed in OSD.
Layout is not detected at startup, I had to use manual detection otherwise it appeared as EN-US initially. After that is seems to display dead keys in OSD but the other regular AltGr chars still don't appear.
Some characters are missing from OSD, dunno exactly in what conditions. And the previous report with capitals sometimes appearing as lowercase in OSD happened to me too in the past and it may be due to script not keeping up with the typing speed but it's just a hunch.
robodesign
Posts: 214
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

Re: [Script] KeypressOSD - Display key press on screen

01 Jan 2018, 16:45

Thank you very much for the report!

I began working now on improvements for slow PCs and to make it detect more reliably modifiers (Shift, AltGr) when typing. I already made good progresses today. Hope to be done in one or two days.

Best regards, Marius.
User avatar
Drugwash
Posts: 400
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [Script] KeypressOSD - Display key press on screen

02 Jan 2018, 09:48

There's still "UInt" instead of "Ptr" in GetDC() and ReleaseDC() calls inside GetTextExtentPoint().
In GetClientRect() inside GuiGetSize() you need "Ptr" for both MyGuiHWND and &rect.
Generally, when borrowing functions from the old board (and not only) you should check with MSDN for data types, since much of that code may be unoptimized for x64 usage in terms of data types and/or structure sizes/alignment.
There are also some superfluous conditions that waste CPU time, such as
text_width := (text_width > maxAllowedGuiWidth) || (text_width > maxAllowedGuiWidth-growthIncrement*2) ? maxAllowedGuiWidth : text_width
which could be simplified to
text_width := (text_width > maxAllowedGuiWidth-growthIncrement*2) ? maxAllowedGuiWidth : text_width
You've modified CreateFont() in GetTextExtentPoint() in a bad way, the value for fnWeight being now uncommon (10+1*bBold) instead of the old correct one (400+300*bBold) - see the predefined values at MSDN. There may be some bug elsewhere related to window width calculation if it doesn't yield the right result with the standard font width values.
However, since the values for bBold, bItalic, bUnderline, bStrikeout, nCharset are (now) unchangeable there is no use in wasting time defining them at every function call when the values can pe placed directly for each parameter.

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


A few lines below you have
GuiHeight := (GuiHeight>maxHeight) ? maxHeight+1 : round(GuiHeight)
which I think should have maxHeight-1 instead, unless I misunderstood something.
There's no need for Round() in GuiGetSize() since the values retrieved by NumGet are set to be "Int". It only wastes CPU time.
GetKeyboardLayout() returns a DWORD not a Handle so return type should be "UInt" or omitted altogether. As such, ToUnicodeEx() should use an "UInt" for last parameter (dwhkl) type.
GetWindowThreadProcessId() requires "Ptr" for both parameters even if last one is set to zero (it's optional, type would be "UIntP" pointing to a DWORD/UInt variable if it were used). There are more instances of these calls where parameter types are wrong, please check the script throughly.
There probably are other such issues in the code, I'm still looking through it. I think I already signaled at least some of these issues earlier, I thought you'd have fixed them by now.

I'll try to prettify the code, make it more readable (before I get too drunk, that is :D ).
burque505
Posts: 177
Joined: 22 Jan 2017, 19:37

Re: [Script] KeypressOSD - Display key press on screen

02 Jan 2018, 16:06

Hi Marius, sorry I've been out of touch. That last post was from the most recent update. I'm running Win7 Pro 64-bit on a fairly ancient machine (2008?) with 8GB RAM, which is not really that slow, considering its age. Unlike its owner ... :(
Regards,
burque505
User avatar
Drugwash
Posts: 400
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [Script] KeypressOSD - Display key press on screen

02 Jan 2018, 16:32

Whoa, 8GB on a single machine?! I don't think I can gather that much from ALL my working machines (about six or seven).

I just noticed a strange bug that I always thought was speed-related: starting (and continuing) typing with a capital letter results in OSD not appearing at all. Starting with a lowercase and continuing with capitals brings up the OSD. This was working in v3.90 which I'm testing right now, stopped working in v3.90.5 and later. Darn, I'll have to investigate that, but probably tomorrow because I'm already tired after all tests and fixes and whatnot.
[EDIT]
Found the problem: commenting the first line below will fix the bug. That line doesn't exist in v3.90. BTW, I'm always in typing mode.

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

; if (OnlyTypingMode=0)
key := (GetSpecialSC(key) || GetSpecialSC(key)=0) ? GetSpecialSC(key) : key


Here's what I've done so far (extension ah1u is as associated on this machine, change back to ahk or whatever you have there for AHK_H):
keypress-osd-ahkH 3.91.5.1.ah1u.7z
(31.01 KiB) Downloaded 7 times
robodesign
Posts: 214
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

Re: [Script] KeypressOSD - Display key press on screen

02 Jan 2018, 17:39

Hello!

Thank you VERY much, drugwash!!!

Yes, that's a silly regression I have not discovered.

Can you please be more specific what fixes you made?

I managed to make even more progresses on the script today (with respect to a much more reliable detection of modifiers) , but not enough to release it. I had many delays today with work, because I had many guests. Holidays are not yet completely over.............................. Brr.

Best regards, Marius.
User avatar
Drugwash
Posts: 400
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [Script] KeypressOSD - Display key press on screen

02 Jan 2018, 17:58

You're welcome. :)

I should've attached the original file too, for an easier comparison; did it now. Can't say precisely what's fixed and what's changed, I just went with the flow. Basically there were fixes for data types in DllCalls, a small optimization in Shift press detection, fixed the above-mentioned bug with capitals not showing in typing mode, fixed incorrect OSD width when Text width factor was 100 or close, fixed colors in color picker to start with old color when available, added option to manually select and load a different script on Reload when the current was renamed/moved/deleted and dunno, maybe something else or not, can't remember. :)

Here's the original file I've been working on, downloaded in the morning through an update:
keypress-osd-ahkH 3.91.5.ah1u.7z
(30.6 KiB) Downloaded 7 times
robodesign
Posts: 214
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

Re: [Script] KeypressOSD - Display key press on screen

02 Jan 2018, 18:31

Wow. Thank you very much for your efforts ! Wow!


I'll check it out in the morning. Looking forward to it.

Best regards, Marius.
User avatar
Drugwash
Posts: 400
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [Script] KeypressOSD - Display key press on screen

02 Jan 2018, 18:39

Eh, no worries, I was just bored - holidays have not come to me yet (would they ever). :)

Please test thoroughly, I don't have an x64 machine to test on.
robodesign
Posts: 214
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

Re: [Script] KeypressOSD - Display key press on screen

03 Jan 2018, 11:51

Hello, followers! ;-)

Here's the new version of the script. Much has changed under the hood.

// KeyPress OSD - CHANGELOG

Download AHK file from or use the Update now option:
http://marius.sucan.ro/media/files/blog ... ss-osd.ahk
Please use AHK_H v1.1.27 [unicode] to execute this script.

by Marius Sucan (robodesign.ro)
v3.93 (2018-01-03)
- substantially changed how Shift and AltGr are detected when typing; it should be much more reliable; it buffers the events more orderly;
- simplified the error handling of script file missing; I do not want the user to pick the new file :-)

by drugwash [from the AHK forums]
v3.92 (2018-01-02)
- various bug fixes, in particular for DLL calls
- improved OSD size calculations
- fixed regression with AltGr and Shift when typing mode only is enabled
- improved color pickers; now, they behave as expected, always starting from the custom color
- error handling when file is missing when attempting to reload; it asks the user to pick the script again...

@burque505. Please test this new version. I would be amazed if AltGr and Shift still do not work for you. In all my tests so far, they work very reliably. Although... I changed almost nothing regarding dead keys.

@drugwash. THANK YOU VERY MUCH for your help! As a side note... I have 32Gb of RAM :-).

P.S. I am on GitHub https://github.com/marius-sucan/KeyPress-OSD .

Best regards, Marius.
User avatar
Drugwash
Posts: 400
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [Script] KeypressOSD - Display key press on screen

03 Jan 2018, 16:36

I do not want the user to pick the new file
Well I do, it's pi$$ing me off because I often rename the currently running file before a manual update or during tests and it's a waste of time to open file manager and navigate to the folder to select the right script when it could be done in two clicks - that's called efficiency. A more elegant solution would've been to make it optional, let the user decide what to do in that situation.

The update routine is annoying, it's leaving garbage behind - three folders in %Temp%. I don't like that. Not to mention the flags in the CopyFile() method are useless when dealing with zip files - as per MSDN - so it would still display the copy dialog and the overwrite confirmation which I also don't like nor want.

Strike three: GitHub. No. Timeout on download? What's that: anti-poor measures? :(

Guess I'll be on my way. Down. Enjoy your 32.
robodesign
Posts: 214
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

Re: [Script] KeypressOSD - Display key press on screen

03 Jan 2018, 16:44

Hello, drugwash!

I uploaded the code and prior releases on github such that I can get more visibility and more feedback, from other sources as well. I have been requested this by some people. It's not a measure against poor people or you.

I'll add again that feature, to request the user to choose the file when it's missing, in the next release.

Please let me know how AltGr and shift work on your system. I really need feedback on this.

Best regards, Marius.
burque505
Posts: 177
Joined: 22 Jan 2017, 19:37

Re: [Script] KeypressOSD - Display key press on screen

03 Jan 2018, 17:08

Hi Marius, to me it looks like everything is working, both Shift and AltGr (which is just RAlt on mine, of course) work just fine. Just one thing - there is a long delay before a new keyboard assignment is recognized. That's an extremely minor inconvenience. It just stops the OSD for a little bit. I tested English, German, Russian, Spanish and (to the extent my experiments mean anything) Romanian.
Regards,
burque505
robodesign
Posts: 214
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

Re: [Script] KeypressOSD - Display key press on screen

03 Jan 2018, 17:30

Oh, that's really great to hear. Thank you very much for your feedback, burque505.

Yes, I am aware of the longish delay between language changes. If you want to reduce it... at keyboard settings, activate silent mode and it will be quicker.

Best regards, Marius.
User avatar
Drugwash
Posts: 400
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [Script] KeypressOSD - Display key press on screen

03 Jan 2018, 17:40

Delay on keyboard detection seems to be present here too. Not very long but longer than in previous versions. I don't switch layouts since I only have one so to me it's not that much of a bother, but for other people it may be. Activating silent mode to reduce delay may not be desirable when user wants to make sure they did switch layout; some people may still hide the taskbar so they don't see the (small) visual cue and rely on the OSD.

Dead keys appear correctly in both OSD and application, with the same old mention that for me they always appear instantly and in a sequence in the application, while the OSD displays all of them in the same place (that is, caret does not advance as it does in the application), but that's probably due to the OS quirks so don't bother.

AltGr seems to work correctly too. I'm afraid to try too many combination, this stupid browser has a lot of Ctrl+Alt+[x] hotkeys and some could make damage.

Some extensive testing would be in order but for now everything seems alright. Time to hit the sack.
robodesign
Posts: 214
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

Re: [Script] KeypressOSD - Display key press on screen

03 Jan 2018, 17:49

Thanks a lot for your feedback, drugwash. I am happy to hear positive feedback, that the work I've put into this new release pays off. And again, thank you very much for your work on the script.

If you (or anyone here) find(s) any other issues, please let me know.....

Best regards, Marius.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: JasonDavisFL and 14 guests