[Script] KeypressOSD - Display key press on screen

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

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

19 Jan 2018, 14:31

Hi Marius,
Testing new version. No failures now with U32 (maybe a glitch on my machine before? Don't know. It's gone, though).
Now, ANY dead key typed at the BEGINNING of a line will result in [Dead key] in the OSD. But not in any subsequent keypresses on the same line.
All languages.
Regards,
burque505
User avatar
Drugwash
Posts: 446
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

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

19 Jan 2018, 14:38

Haha, I was about to report 'Never display OSD' not working, just stumbled into it minutes ago when trying to get the OSD out of my face. :)

I'm close to finding an alternative to the ugly caret but wasted hours trying to find out why a bloody message (EM_POSFROMCHAR) doesn't work at all, to no avail. :(
[EDIT]Is that message really Vista+ ? That would explain it. In that case, what would be the best alternative to it, except GetCaretPos() which doesn't work when Edit control is not focused?
Darn, I had the wrong constant because somehow certain messages are defined twice and they are very different in RichEdit vs Edit (see here)!

Is there anything you could do with this piece of code?

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

Last edited by Drugwash on 19 Jan 2018, 17:08, edited 4 times in total.
robodesign
Posts: 274
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

19 Jan 2018, 16:18

Hello, guys:

@burque: that is correct behavior, if only typing mode is off. Is it off or on?Please also let me know if you have alternative hooks enabled. Glad to hear you get no crashes anymore on u32.

@drugwash: ooowww, that's nice to hear. I hope to like the solution ;-). Really curious about your new version. I don't know exactly what you are talking about, hehe.

Edit. Please make sure there is a way to display the dead key symbol when pressed.

Edit. Two. Do what with the code? Please be more specific. Drugwash.

Please also note, the edit field gets all flickering with big fonts when navigating with the actual caret. At least, in my tests.

Best regards, Marius.
Last edited by robodesign on 20 Jan 2018, 05:03, edited 1 time in total.
User avatar
Drugwash
Posts: 446
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

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

19 Jan 2018, 17:26

Sample code is posted above. It works by retrieving the hidden caret's position in the string and then moving the specially-styled text control at that position. A timer is blinking the fake caret while hiding the real one when the Edit is focused.
The code contains some extra checks to make sure position is within boundaries and doesn't jump twice when focused.
Dunno how you actually insert the dead key symbols in the text string, didn't look much at that side of the script but I hope it would work.
There are basically only three colors available for the fake caret, using styles 0x4, 0x5 or 0x6 which produce solid block character. Styles 0x7, 0x8 and 0x9 produce empty blocks of the same respective colors, visible when fake caret width is larger than 2, but those styles may only be useful for very large font sizes or fonts with large spacing between characters.

Anyway, that's just a proof of concept, no idea if it will fit the main script or not; as mentioned above I wasted a lot of time trying to make things work and now I'm too tired for other tests. If you can fit the relevant bits to the main script and test it would be fine.
There's no flickering here in the sample with Arial 24 but maybe text is too short or font too small. And remember it's XP, who used to be sluggish and flicker in older versions. Just test the sample, modify font size and text string as needed, see how it behaves. The original caret should not be visible even when Edit is focused.
robodesign
Posts: 274
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

19 Jan 2018, 17:40

Merci beaucoup. I will test it out tomorrow. Really curious about it. Thank you very much.

Good night :-)
robodesign
Posts: 274
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

20 Jan 2018, 04:17

Hello, drugwash!

I just tested the prototype you posted. It flickers only when the text gets scrolled, but not for every movement. Now, I wonder how and if it can be adapted to work with making selections, displaying dead key symbols and finally, manage unicode chars formed with an additional modifier char.

What do you think of these? can it be pulled off?

PS. Being just a prototype, no surprise for it being a buggy ;-)..., when I reach the end and press a few times more Right, it does not go Left when needed. And the caret has the tendency to be placed a little on top of the letters.

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

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

20 Jan 2018, 05:41

Oh well, that's the abomination for you. :) It doesn't flicker at all here, maybe just a tiny bit when reaching a far end of the control and has to bring a new batch of characters into view. The original caret may flicker in the background (when Edit is focused) since it's being hidden on a timer basis not when Left/Right are pressed.

Are you sure you got the very latest version of the sample code? I've modified it a few times last night since first posted.
As for the caret being placed on top of characters, that may be a matter of API miscalculation or a too large fake caret width. Original caret is 1px wide, I made this one 2px just to be more visible but width can be modified in script. Otherwise it always takes the position of the original caret so if that one is off, the fake one will be off too. And it may also depend on font type, native italic fonts or those with unusual escapement may be overdrawn, but same would happen with the original caret. If it's not that then maybe you'd post a screenshot, if possible, so I could understand better.

Basically the code just follows the original caret position, so in the main script you'd only have to update current caret position using EM_SETSEL instead of inserting the ugly caret character that doesn't show up properly in many fonts, and then update the fake caret position. All those extra checks in the sample code may not be necessary. There will be no change in how characters are inserted in the string to be displayed, no messing with dead chars, no other fancy stuff.

For now I'm busy searching for information on other keyboard layout related issues so I won't be abe to operate those changes in the main script, especially when I'm not familiar with the string manipulations and all that in the script. And anyway this is not time critical.
One thing to check would be how the main script behaves with this change in, considering XP would have to deal again with an Edit, since there's no original caret in a Static (Text) field.
robodesign
Posts: 274
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

20 Jan 2018, 06:13

Hello!

@drugwash: I can see this prototype as a future solution... but it needs work. However, I am unfamiliar with these things. I will wait for you patiently and see what you come up with.

I made some small changes to the script today:

v3.99.7 (2018-01-20)
- reduced further flickering when using Align to right for the OSD.
- now it always indicates when a modifier is pressed, even in only typing mode by changing the text caret to a gray block :-).

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

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

20 Jan 2018, 08:49

Yes, I figured it would need some work and I guess 'lola' will be dismissed. :)
It'll take a while before I actually get to that part so you may take advantage of this and fix/modify/add whatever needed in the mean time.
robodesign
Posts: 274
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

20 Jan 2018, 09:18

Yes, Lola and caretzescu.....:-)

Now, I only want to add keyboard shortcuts customization. And I have an idea how to make it better synchronize with the host app when jumping between words. That's all I have planned.

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

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

20 Jan 2018, 19:59

Maybe this kind of live, accurate detection would be more useful than the hardcoded languages file:
20180121025623.png
20180121025623.png (23.31 KiB) Viewed 230 times

There are still details to take care of so I won't be posting any code yet.
No news o the fake caret, didn't work on it today… erm, I mean yesterday since it's 3AM already.

Oh and where did the caret halo code go…? :?
robodesign
Posts: 274
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

21 Jan 2018, 06:58

Hello!

@drugwash: You mean layout name detection without hardcoded names? That would be LOVELY ;-). I would be happy if dead keys detection could be automatic as well, without hard-coded VKs. With both, then we could eliminate the lang file entirely. Dream like.

@drugwash: the caret halo stuff was moved into mouse functions file. I want the main OSD thread to be as light as possible.

I made a new version, I almost had it ready yesterday, but glitches kept me from releasing it.

v4.01 (2018-01-21)
- bug fixes and improvements for the new feature implemented yesterday
- improvements [hopefully] to the handling of Ctrl+A/Z/X/C/V... again

v4.00 (2018-01-20)
- [new] option to send keystrokes that reproduce text changes operated in the typed OSD content, when making caret jumps with Ctrl + Bksp / Del / Left / Right. This helps to ensure a consistent experience across apps and to remain in synch [not enabled by default, for now... I might change this]

The new feature is usable in most scenarios. I think I should have it on by default.

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

@drugwash: On my plate, I only got now to add Customizable kbd shortcuts. But I will wait for your new edition, I am very curious. Make them hard-coded stuffz vanish into thin h-air! I will make new releases only if I get new bug reports or when I fix bugs I find myself.

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

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

21 Jan 2018, 10:24

Every OS version has its own list of supported languages and layouts, and all that information can be found in the system. It's just a matter of proper API (and other information) to reveal it. I still haven't figured out how to properly read and use some registry keys, so my test script mostly works but with possible exceptions.

There is a clear distinction between languages and layouts, and you need to understand it for a proper implementation of detection and display.
I didn't yet delve into the world of dead keys and composed characters, that will be a complicated matter. I need to first finish a few things I started before I do that. Actually I kinda have a thing with unfinished businesses.

You need to add a reliable mechanism for updating related files when any of them were changed on your side from one version to another, otherwise the script will run crippled or not at all. Currently it doesn't check for the mouse-functions version/size/hash or the caret halo routine presence hence the option won't work, it silently fails. And remember people may modify parts of the additional scripts (and/or the main script) and may wanna keep them for future upgrade/merge so make backups, don't just overwrite when updating. ;)

I hope 'customizable keyboard shortcuts' doesn't mean more of script's own hotkeys. I hate hotkeys! (I know, it's strange considering where we are now, but that's how I feel due to too many bad implementations in too many applications; actually this stupid browser just crashed while looking in the menu for all those damn hotkeys that cannot be disabled, so I had to take a partial screenshot and type this all over again)

Don't wait for me, I'll be working on various bits and pieces outside the main script - although more or less related to it - and it may take quite some time before deciding they could be merged in. There are also a few old quirks that need to be fixed in my mod, related to dragging, reading/saving settings, settings panels. I don't like frequent bugfix versions, people get confused and wary. So do your things, I'll do mine and we'll see where we get to. ;)
robodesign
Posts: 274
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

21 Jan 2018, 11:29

Hello!

Okay, thank you.

Yes, there's a clear distinction to be made between kbd layouts and languages.

When you run the update it ask if you want to abort ;-). I was about to lose a few days of work, because I clicked by mistake Update. Since that day I made it ask first. It downloads the zip file and un-packs it, over-writing everything. Apologies, but I do not plan to work on an advanced update system.

I am surprised you do not have the caret halo working. It should work. I suppose you checked the mouse-related functions file for CaretHalo(), right? It should be there.

Okay, I won't wait for you then, but... I am quite anxious about your edition. Today's post, with that screen shot just blew me away and the potential for that caret re-work.

I intend to do something very simple regarding shortcuts customization, you'll probably be disappointed ;-), how banale it will be. I won't add more shortcuts, actually I might turn off a few [by default].

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

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

21 Jan 2018, 12:08

When you run the update it ask if you want to abort […] It downloads the zip file and un-packs it, over-writing everything. Apologies, but I do not plan to work on an advanced update system.
I want to update, I just don't want to lose the possibly modified files. One may click on Yes by mistake, forgetting they have modified something. Yes, the unpacking routine also asks whether it should overwrite all or not, but that's another quirk that bugs me, because it shouldn't ask (according to the flags that M$ decided not to take into account) and I'd like to get rid of it. So that's another thing I'll have to do myself (create Backup folder, move files in there, then allow unpacking, at which point I have a backup and also no annoying overwrite confirmation). Ah, that's a very hard thing to do, dunno if I'll be able to do it! :P

Let me elaborate a bit. User downloads the updated main script manually from the links above. Saves it in the dedicated folder and then launches it. At that point, the script has no knowledge that the additional scripts had been modified by the user or updated on your site so it'll run as usual or at least it'll try to. Since there are no checks whatsoever in regard to additional scripts' versions or contents, the main script may run buggy or not at all.
So no, I have no CaretHalo() function in my mouse-functions file because the main script didn't tell me it needed a new, updated version of that file. And I didn't manually update because I'm not a Win10 user already accustomed to frequent updates (and assume I hadn't read all the forum posts to see if such change was mentioned or not; the changelog certainly stopped a few versions ago at 3.99.5 so no mention in there either). Capisci? ;)

Again, the language/layout detection you saw in the screenshot is a standalone script thrown together for testing purposes (same as the one for fake caret), it's not yet in a shape suitable for inclusion in the main script. I could publish it here if you really want but as mentioned before, some things are not quite right and other detections are necessary too (such as when the user adds or removes languages/layouts from the Control Panel).

As long as you don't add more shortcuts/hotkeys I'm happy. :)
robodesign
Posts: 274
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

21 Jan 2018, 14:42

Hello!

I searched on the internet how to detect KBD layout names and I came up with a solution of some sorts:

RegRead, langFriendlySysName, HKEY_LOCAL_MACHINE, SYSTEM\CurrentControlSet\Control\Keyboard Layouts\%kbLayoutRawCode%, Layout Text

I already implemented this, but of course I want to see your sample script. Maybe what I did is foolish ;-). I must test it on Win7 and WinXP.

The keypress-files.zip is of out-most importance to update each time, if you do it manually. Here it does not give me any additional prompts [to overwrite files]. And yes, I forgot to update the external change log file. Sorry. Updated now. And the zip. [attention: new language file]. I removed all the language names, except for those kbd layouts that are supported. When I made the list I distinguished some layout names.

v4.02 (2018-01-21)
- added support for (w/o Shift+) Home/End when the new option is activated [Send keystrokes to host app to reproduce OSD content]
- simplified keyboard detection mechanism even more; it reads from the registry the Keyboard Layout names, for unsupported ones; many thanks to Drugwash for the idea

PS. Edit. I think it would be better to use from there [the registry] the value from: Layout Display Name. The value is something like: @%SystemRoot%\system32\input.dll,-5210 . But, of course I have no clue how to transform that into the string that the DLL call returns.

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

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

21 Jan 2018, 15:57

You're getting close. ;) Here is the test script as it is currently, dunno how the day went by without me doing anything useful:

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

Layout Display Name would be the preferred string to get, if it exists. Next best is Layout Text. The former is not present for custom layouts, only the latter, so the script should take this into account (mine does).
One problem remains to be solved: the substitutions. I attempted something but it's more guesswork than reliable code. Run it on your systems, see how/if it works and if results are correct. Any change to the current language/layout should be promptly displayed in the statusbar, regardless of the focused application. But that's using a timer and I don't like it; been looking for an elegant solution yesterday but couldn't find one other than global hook using separate dll.
robodesign
Posts: 274
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

21 Jan 2018, 16:03

Okay, thank you very much!

I will look into it, tomorrow. However, the layout name is not very important to be displayied in real time, for now. Because... We have pressing issues with changing the hotkeys as required, in real time - to bind to new regional keys and change / update dead keys. These are the important aspects that would need to be fixed/found solutions for, if we want to eliminate restarting for every kbd layout change. Ideally, it should not rely on any hard coded dead key. If it would get to this point, it would be purr....fection...

Best regards, Marius.
robodesign
Posts: 274
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

22 Jan 2018, 11:02

Hello!

Today's new version brings bug fixes, considerably important ones:

v4.031 (2018-01-22)
- [new] option to mediate navigation keys for slow computers: left / right, backspace / delete, home / end
- further improvements for keyboard layout name detection, thanks to Drugwash
- improved the compatibility of the features that enable synchronization with the host app, for foreign layouts
- various bug fixes regarding enable/disable the displaying of single keys, never show OSD, and the typing modes; it was a mess
- as a consequence, show single keys shortcut toggles now never display the OSD;

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

@drugwash: I added two functions from your sample script into mine. Now, it gets the MUI lang name, for unsupported layouts. I was already handling substitutions properly, see my script. You can test by removing the content of lang.ini [except for LoadedLangz var] and it will recognize all substitutions with proper names. Your sample, indeed, did not get the proper names for substitutions. Thanks for the link, but I am not good with DLL calls as you are, by far.


Best regards, Marius.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Bon, jcash and 17 guests