[Script] KeypressOSD - Display key press on screen

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

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

08 Jan 2018, 17:23

Hi Marcus,
Everything works in English, Spanish, Romanian, Russian, German for me.

BUT - I tried disabling the highlighted cursor in keyboard preferences. Any time I make a change in keyboard preferences, the typing preferences change without my authorization. Specifically, "Disable typing mode (by shadowing host app)" is checked automatically - I don't want that. "Do not bind (ignore) known dead keys" gets unchecked. I don't want that either.

The reason I don't want those changes (which I didn't make myself) is that the OSD displays only single capital letters until I reset the typing preferences again.

Still on Win7, 64-bit, 1.1.27.01 AHK_H (v001).
Regards,
burque505
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

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

08 Jan 2018, 17:38

disabledColor in VerifyMouseOptions() is not used anymore anywhere in the script, commands that used it were modified and it became unnecessary.
You applied the file checking loop I devised but forgot to delete the old version, thus duplicating the check.

There's something fishy in the Typing mode panel, settings get screwed up when disabling/enabling caret halo in Keyboard panel and applying (disables 'Typing mode only', 'Insert the dead key', enables 'Enter and Escape keys…', 'Do not treat dead keys…', 'Do not bind…' and possibly others I don't use or notice). This is bad and is only happening due to a bad call to VerifyTypeOptions() in ShowKbdSettings(), that is wrong function for the wrong controls. I see burque505 reported it too. I've fixed it in my version below. :beard:

The ugly 'caret' sign still appears - maybe it's a font problem? I use Calibri for the moment. After switching to Arial it appears correctly but that should not happen, if user chooses some strange font what would they see?

BTW, relevant options would regard the newly added caret hilighting which kills the eyes as it is now, with that constant flashing and low transparency. ;)

Here's the modded (and fixed) version:
keypress-osd-ahkH 3.97.5.1 mods.7z
(36.33 KiB) Downloaded 13 times

[EDIT] Fixed issue with OSD staying visible after dragging (ah,those variables with sneaky names…):
keypress-osd-ahkH 3.97.5.2 mods.7z
(35.66 KiB) Downloaded 14 times
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
robodesign
Posts: 357
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

09 Jan 2018, 04:22

Thank you very much to both. Working now to merge the changes into main release. meanwhile... I will also make other improvements.

@burque505: do dead keys work in the host app without checking Do not bind dead keys?

@drugwash: fixed those silly errors now and merged your changes for files checking - thank you very much! Total Commander is good. Justed tested its compare functionality - all good ;-).

EDIT: forgot to mention.... the changes you made to the mouse, visual clicks, breaks them.

EDIT2: You no longer have the double click bug and I see you've optimized the code for dragging the OSD. I will merge these into the main build. Thank you very much.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
My home page.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

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

09 Jan 2018, 10:05

You're welcome. :) And you're right about those mouse-functions changes, didn't test them enough, sorry. However, while there I just noticed GuiGetSize() uses UInt instead of Ptr for both parameters, which is wrong for x64. How on earth it worked until now is beyond me. :)

Glad you like TotCmd, I find it much easier to work with although it has his limitations and shortcomings (file comparison-wise).

I'm gonna try to implement some additional settings panel for those mouse functions, to avoid direct script editing. I know you said there are too many options already but look at the bigger picture: people have different themes/visual styles and the defaults not always match, not to mention personal preferences, so they need to be able to adjust everything that can be adjusted in order for all those functions to be really usable for them personally. This goes from OSD colors/font/size to mouse functions colors/alpha/size, because this script has already become more than a mere OSD showing text. ;)

Let's see if/what I can crop up. :)
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
robodesign
Posts: 357
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

09 Jan 2018, 10:16

Okydoky, looking forward to your work.

I also should note, the new font-listing function I have does not crash anymore on my 32 bit AHK.

I am going to remove some options in the OSD configuration and add more to the typing mode.

I also integrated much of your dragging routines, I like them now :-). However, critical is required here, to have the drag-function work... No idea why.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
My home page.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

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

09 Jan 2018, 10:33

the new font-listing function I have does not crash anymore on my 32 bit AHK
You mean EnumFontFamiliesEx() implemented in last version? I didn't have much time to look at it so it got ignored for the time being. However I had no crash here on XP with old EnumFontFamilies() and I do have a lot of fonts of various types. I'll have a look at both at some point.

What exactly are you going to remove from OSD config? I think they're all useful.

Which Critical are you referring to, more precisely? The one disabled in MouseMove()? I'll test a bit more but at first sight that line can be removed now, it seems to work well without it here even with Edit instead of Text (that 'debug' variable sure makes things easier :) ).
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
robodesign
Posts: 357
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

09 Jan 2018, 15:17

Hello!

I am VERY PROUD to announce great improvements:

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.


by Marius Sucan (robodesign.ro)
v3.98 (2018-01-09)
- [MEGA-COOL-NEW - yes, I am silly @rommmcek: MANY THANKS] option for alternative mode to hook to keys. This enables full support for dead keys. Combinations are always displayied. The dead key symbol is displayied and inserted into the OSD [when needed] only if the option "Do not bind to dead keys" ïs not enabled. This new option is now enabled by default.
- [new] option to send keystrokes in realtime to host app when using alternative typing mode; it does not work in all apps
- improved the way text is sent from the OSD to the host app when using Alternative typing method, much faster and does not rely on the clipboard anymore.
- removed two silly options from OSD appearances settings window and replaced them with one: Align OSD to the right side.
- other bug fixes and improvements, thanks to drugwash! ;-)

Many thanks to drugwash and rommmcek for pointing me towards better solutions! The solution from TypingAid, for capturing key strokes, is highly beneficial/useful and I was able to make great use of it. Everyone, please test it! :-). Bugs are likely to be present regarding the new hook, .... please report them.

PS. Make sure you have keypress-keystrokes-helper.ahk in keypress-files folder.

Best regards, Marius.
Last edited by robodesign on 09 Jan 2018, 16:37, edited 1 time in total.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
My home page.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

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

09 Jan 2018, 15:59

Now I'm getting two weird carets: one behind the text and one after, if I use a dead key. Under some circumstance the dead keys stop being displayed.
And not even Tahoma can display that caret, I get empty squares instead.
Then, it seems to reset the text when typing lowercase 'a', everything typed before gets erased (this bug happened before a few versions back). Alternative hook doesn't seem to influence this bug, it happens whether it's enabled or not. Man, this version is screwed up badly. Back to the drawing board. Sorry.

P.S. The values retrieved from the RECT structure in GetClientRect() are not pointers, they are integers (UInt) because they represent the dimensions of the client area of a window (and as proved somewhere around these boards any values larger than 32742 would crash Win10 while Win9x runs circles around it, so they could safely be regarded as UShort). Only the parameters passed to the function have to be pointers: a handle to the target window and a pointer to the RECT structure that receives the coordinates.

I'm getting too tired for this.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
robodesign
Posts: 357
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

09 Jan 2018, 16:32

Please update to 3.98.01. I found quite some bugs too and I fixed em.

Please update me on this.

You have dead keys with AltGr. I have not yet tested these.

What I did in this new version is to make a new thread that listens to keystrokes using the command input, as seen in the source of typing aid. In the main thread, I receive, via sendmessage / onMessage 0x4a each keystroke. However, I just realized this is very sluggish /slow and it is prone to skip keys. In Typing aid, the guy had a loop. I don't know how exactly I could integrate this into my main code and still have the interface update, to avoid using multiple threads that communicate poorly. ..

@drugwash. I would be happy if you could help me with this issue. And help me nail down the bugs you are experiencing. Please. Thank you.

EDIT: More bug fixes current version is 3.98.02... but still got a few left, including a crasher. EDIT: fixed the crasher.

Best regards, Marius.
Last edited by robodesign on 10 Jan 2018, 16:05, edited 1 time in total.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
My home page.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

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

10 Jan 2018, 09:41

Sorry, I don't have time for this, my main monitor just crashed this morning and I have to fix it.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
robodesign
Posts: 357
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

10 Jan 2018, 15:34

Hello!

No problem, good luck fixing it!

Yesterday´s release was rather ... an alpha version :-) .... Had to fix many things and I still got a few... Now, I would label it as a beta ;-).

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.

Today's minimal change log:
v3.98.05 (2018-01-10) - beta
- bug fixes and improvements to yesterday's release; now it's working much better; still got some bugs left related to AltGr and Alternate hooks.

All dead keys (with or without shift) should work in any mode. And general typing, of course. If these don't work, let me know.

The dead keys associated with AltGr work now, if alternate hooks is disabled. Will make them work with the alternative hook as well, hopefully... tomorrow.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
My home page.
robodesign
Posts: 357
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

11 Jan 2018, 16:06

Hello, guys!

// KeyPress OSD - CHANGELOG
by Marius Sucan (robodesign.ro)
v3.98.07 (2018-01-11) - release candidate
- many bug fixes; as always, too many too list here; i would waste time keeping track of them
- removed useless options from typing settings:
-- immediately change to alternate typing mode, when typing [because it's too unreliable]
-- do not treat dead keys as a different char [the recent changes made it useless]

--------------------------------

Another update with lots of fixes... Hopefully it runs fine.

I fixed the problems with the AltGr Dead Keys.

On my system, everything works fine now, as far as I can tell. I tested it with Sticky keys on/off, alternative hooks on/off, bind/don't bind dead keys and so on - variations of settings and different keyboard layouts.

Tomorrow I will begin testing it on various systems: Win 7 [in VM and my old PC], on my laptop [win10] and XP [in VM]. Of course, with various settings. When I am done with these tests and fixes, I am going to really need your feedback.

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.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
My home page.
robodesign
Posts: 357
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

12 Jan 2018, 16:12

Just a quick update:

v3.98.08 (2018-01-12) - release candidate 2
- minor bug fixes

Today I finished testing with Win 7 in virtual box. I managed to find some new bugs and fixed em.

@drugwash: do you know how to assign a keyboard layout to the current GUI/window of a script?
See this code:

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



When the user clicks on the button, the layout should change... Thank you.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
My home page.
robodesign
Posts: 357
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

13 Jan 2018, 15:08

Hello, amigos!

Here's the so-called final version:

v3.98.5 (2018-01-13) - final
- [new] reorganized Typing mode settings window. Made it more informative and better organized and clean.
- [new] option to change typing delays required internally to allow host apps to receive dead keys properly.... by changing this multiplier, you can make dead keys work well, even if "Do not bind dead keys" is activated.
- minor bug fixes

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.

@burque505, @rommmcek, @drugwash, @ozzii (or anyone else).... Please test this version and give me feedback. I want to finalise this project. Please test it with default settings. If dead keys do not work in the host app, increase the typing delays multiplier. Please also read the following:

Q: How does this application work?

A: KeyPress attaches [using keyboard hooks] individually to each key and modifier, on your keyboard and listens/waits for these to be pressed. When a key is pressed, it is displayied on the OSD. When typing, it uses Windows APIs to get the key names, based on the current keyboard layout. This applies as well when using Shift, AltGr or Caps lock.

The application does not use the caret specific Windows APIs to detect where the actual text cursor [caret] is in the text field of the currently active application, because most applications do not make use of these APIs - to report the caret position. It also does not detect if a text field is active or not.

about initialization:

When the script initializes, it goes through all the Virtual Key codes and tests with ToUnicodeEx() and GetKeyName() if there's something to bind to (a key name).

In the language file, I made list of VKs for dead keys, for around 70 keyboard layouts. I made it to bind distinctively to this type of keys. At initialization, the script generates a list of dead key names that later, is used to display the appropriate symbol. One cannot use ToUnicodeEx() each time such a key is pressed, to display their name/symbol, because they no longer function properly in host apps.

About the main typing mode.
The main typing mode hooks to each key using the Hotkey command from AHK, by Virtual Key (vk) and different modifiers. For the Shift and AltGr key combinations, the script binds distinctively, because it must be able to catch these keys orderly and always be able to determine what key name to display using ToUnicodeEx(). if it would bind simply with the (*) wildcard, dead keys cease to function and on slow systems, modifiers detection becomes unreliable. By binding specifically to each modifier and key, based on the prefixes from the built-in variable A_THISHOTKEY, it can always ascertain what to display.

About alternative hooks
When alternative hooks are enabled, a different thread runs with a Loop for an Input command limited to one character. This input command is able to capture dead keys combinations (accented letters). For each key pressed, I use SendMessage to the main thread of the script, that uses OnMessage for WM_COPYDATA. The function associated processes the incoming messages / keys. What this secondary thread sends is used only after a dead key was pressed. Thus, it all still relies on the Hotkey command to get all keys and ToUnicodeEx(), except for the accented letters (keys resulted from using dead keys). When the layout is supported and no dead keys are present, this secondary thread is never initiated.

...... Known issues with alternative hooks: This hook does not work with Windows 10, Metro apps, becauset the Input. command does not capture keys properly.

About the alternate the typing mode.
When alternate typing mode is invoked, I create a new window and focus it, to capture keys with two OnMessage hooked to WM_CHAR and WM_DEADCHAR. I no longer rely on the Hotkey bindings or Input command from the secondary thread. When the user hits Enter, I use SendInput {raw}. I do not use {text} mode, because I want the OSD to send what the user sees and not have him surprised by getting something else in the host app.

Known issues: This solution would work in all context, and all OSes, if I would find a way to set the same keyboard layout to my script window as that of the host app. I was unable to achieve this, despite my attempts for the past two days. I can set the keyboard layout for other apps, but not to my script window. I do not know why. For now, this solution works best in Win 10.

Thank you for reading this long message. I know it is tiring how many versions and bugs I come up with ;-).... but I am struggling to make something good... and for this, I need all the help I can get.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
My home page.
burque505
Posts: 521
Joined: 22 Jan 2017, 19:37

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

13 Jan 2018, 18:19

Hi Marius, without alternate hooks (Ctrl+Ins) everything works fine. After pressing Ctrl+Ins, sometimes everything works, sometimes not. ° sometimes does not show in the German keyboard, especially at the beginning of the line. It is, however, nice to see the accented letters in the OSD. ° just now showed up as Shift(2) on the OSD in German with alternate hooks. +eüäö++*#' are fine at the moment.
Ё!"№;%:?*()_+ЙЦУКЕНГШЩЗХЪ/ФЫВАПРОЛДЖЭ,ЮБЬТИМСЧЯ all work fine even with alternate hooks. ª in Spanish shows up as Shift(2) on the OSD in Spanish with alternate hooks (same key as ° in German). ÁÉÍ all show up with a small accent BEFORE the letter in the OSD (Spanish still). @ works fine. áéíóú, same as caps (almost looks like á'é'í, etc., but not quite).
Regards,
burque505
robodesign
Posts: 357
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

14 Jan 2018, 03:54

okay, thank you very much for the feedback... Please try increasing the Typing delays multiplier and see if they work better. Try increasing by 5 each time.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
My home page.
robodesign
Posts: 357
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

14 Jan 2018, 13:58

(waiting for more feedback)
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
My home page.
burque505
Posts: 521
Joined: 22 Jan 2017, 19:37

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

15 Jan 2018, 20:15

Hi Marius, everything is still the same as my last report, with one difference I can't explain. Where before while typing ° with the German layout I got Shift (2). Now I get Shift + $Vkdc. But, as I didn't know last time, this only happens at the beginning of a line, or if °°°°°, Shift + $Vkdc Shift + $Vkdc (2) Shift + $Vkdc (2) Shift + $Vkdc (2) Shift + $Vkdc (2). But if I type, for example, 1° at the beginning of the line, I get 1° in the display also. Something to do with being the first character of a new line, I'm thinking. Spanish: The behavior with German doesn't happen now. Accents look good, and I don't get that á'é'í effect anymore.
Changing the delay time seems to have absolutely no effect on this behavior. I went up to 50. The script is reporting 3.98.6 in the tooltip, is that right?
Regards,
Winter
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

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

16 Jan 2018, 05:13

If you guys follow the development of AHK_L at GitHub you'll see there have been quite a few hiccups with dead keys, hotstrings and so on for the fast few bugfix releases since 1.1.27.00, and presumably AHK_H got those bugs in too, so I'd say let things cool down for a while before screwing this script up even more than it is now and wasting time debugging.

For own script's layout change see this commit, it may give an idea about proper detection of active control - as opposed to active window, as they could belong to different threads in the Win10 abomination - and then you may crop something up, like the following; note that recently GetFocusedThread() has been renamed (and updated) to GetFocusedCtrlThread() as can be seen here:

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



Oh and I eventually managed to fix my monitor(see here) and also borrowed a faster USB 3G modem from a friend.

One last thing: a couple fixes in setColors() and hexRGB():

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.
robodesign
Posts: 357
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

16 Jan 2018, 09:27

Thank you very much guys for your reports and information.

Yesterday I was able to fix the issues with "too many fonts" (when going through many of them)

Today I managed to cut down 5 kilobytes from the script. I am reworking how modifiers are handled. And with this, I will be able to remove one silly option... "sticky keys mode".

Yes, I learned that there's something bad going on with dead keys in ahk. I hope improvements will follow.

@drugwash. Happy to hear the good news. And thanks for the fixes. I will have them in the next release. Probably tomorrow.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
My home page.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Spikea and 16 guests