[Script] KeypressOSD - Display key press on screen

Post your working scripts, libraries and tools
robodesign
Posts: 131
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

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

04 Oct 2017, 14:44

Hello, ppl!

Another new version:

; CHANGELOG:
; by Marius Sucan
; v2.72 (2017-10-04)
; - new option: make beeps on mouse clicks
; - new option: distinct beeper for modifier keys: Shift, Ctrl, Alt, WinKey.
; - new option: beep hidden keys; if you want it to beep even if the keys are not displayed
; - fix: now it always counts mouse clicks and "wheeling"

Script also at: http://p.ahkscript.org/?p=867f287b

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



; AVAILABLE SHORTCUTS:
; Ctrl+Alt+Shift+F8 - toggles "Show single key" option. Useful when you must reliably use dead keys.
; Ctrl+Alt+Shift+F9 - toggles between two OSD offsets: GuiYa and GuiYb
; Ctrl+Alt+Shift+F12 - Reinitialize OSD. Useful when it no longer appears on top. To have it appear on top of elevated apps, run it in administrator mode.
;
; FEATURES:
; - Show previously pressed key if fired quickly
; - Count key presses or key fires and mouse clicks
; - Automatic resizing of OSD/HUD or fixed size
; - Generate beeps for key presses, modifiers, mouse clicks or just when typing with Capslock
; - Indicators for CapsLock, NumLock and ScrollLock states
; - Hides automatically when mouse runs over it
; - Typing mode; shows what you are typing in an expanding text area
; - Dead keys support (partial), option to turn it off
; - Easy to configure with many options:
; - to toggle features: key beepers, key counting or previous key
; - to hide modifiers, mouse clicks or single key presses (which disables typing mode)
; - or hide keys that usually get in the way: Left Click and Print Screen [HideAnnoyingKeys]
; - differ between left and right modifiers
; - OSD/HUD position, size and display time
; - beep key presses even if keys are not displayed

; TO-DO:::::::::::::::::::::::::::::::::::
; features to implement:
; - support for non-english keyboards done
; - when user types single letters, display Shift + (sign or numeric keys) as signs/symbols, eg. Shift + 0, should be displayed as ); done
; - after pressing Shift + [letter] if the following key is a single letter, remember the first Shift + [letter]; done
; - after a Numpad key is pressed, typing mode should begin if the second one is another numpad key; done
; - show a generic symbol for ignored dead keys; helps to clarify one was pressed;done
;
; glitches to fix [by priority]:
; - [regression since v2.52] show Shift as a modifier, as Ctrl and Alt; Shift should behave as the other two; it is never displayed alone and countable; done
; - once a key is pressed, counting of key fires is not initiated after the OSD was hidden for a little awhile; done/fixed
; - make dead keys always work; with the current implementation, the special keys show up seemingly random in the OSD and sometimes in the text field the user types in; done
; - if dead keys support / work-around enabled, once you typed a caret [^], sometimes user gets randomly inserted carets when typing; done/fixed
; - automatic resizing of the OSD/GUI is just a silly hack based on the default font size and the number of typed chars; it often fails to resize properly; done/much improved
; - redraw issues; it still flickers;
; - make it work reliably with sticky keys; if user presses once Ctrl and another key afterwards, it rarely detects the combination on Winndows 7;

PS. Drugwash/Dragoș. I tested the Romanian keyboard layout with the script. No Romanian keys are displayed in the OSD. However, it does not prevent one from using the keys.

Best regards, Marius
Last edited by robodesign on 16 Nov 2017, 05:27, edited 2 times in total.
User avatar
Drugwash
Posts: 307
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

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

05 Oct 2017, 08:24

PS. Drugwash/Dragoș. I tested the Romanian keyboard layout with the script. No Romanian keys are displayed in the OSD. However, it does not prevent one from using the keys.
Well then, since this script's main function is to display the pressed keys, I'd say it's buggy/incomplete.
Any users of other keyboard layouts here (italian, french, turkish, danish, whatever) to confirm the issue?
Guest

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

05 Oct 2017, 08:51

It seems rather logical to me when you study the CreateHotkey() function - it doesn't create any non-English keyboard hotkeys.
So if Ș for example is in your keyboard layout it needs to be added as a hotkey. And that for each language / keyboard layout you wish to add support for.
robodesign
Posts: 131
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

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

05 Oct 2017, 15:22

Yes, there is no real international support.

I just learned that it does not cover a wide range of keys.

I could make (even did so) a huge list of letters/chars specific to Romanian, French, Turkish or other languages, to assign hotkeys to all, in CreateHotkey() function, but...

The problem is AHK gives the error [not a valid key name] when the script tries to assign hotkeys to inexistent keys. So, I would need another function to check if they exist. Can anyone help me with the DLLCalls for this? I need to circumvent getting the error and I was told DLL calls are required for this.

I identified 50 different characters in the alphabet of Turkish, French, German, Romanian, Czech, Polish, Hungarian, Danish, Swedish: à, ă, ą, á, â, å, ä, æ, ß, ć, č, ç, ď, ę, ě, è, é, ê, ë, ğ, i̇, í, î, ï, ń, ň, œ, ő, ø, ó, ô, ö, ů, ű, ù, ú, û, ü, ý, ÿ, ř, ś, ş, š, ș, ț, ť, ź, ż, ž,

Thank you.

Best regards, Marius
robodesign
Posts: 131
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

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

06 Oct 2017, 03:09

okay, thank you. I will try/check those, but I also thought of adding a settings option, where users can simply add a list of chars specific to their language. After all, one needs to edit the settings section to make it suitable to one's needs. I think this way I could safely enable international support and not overly complicate it. What do you guys think?
User avatar
Drugwash
Posts: 307
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

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

06 Oct 2017, 06:54

Things are not that simple. User may switch layouts at any time for any given open application. As you may know, each open application retains its own layout and switching applications will also switch layouts. There is a notification message when layouts are switched (0x51=WM_INPUTLANGCHANGE) and you should hook that notification, retrieve the current layout pertaining to the currently focused application and adjust the script to display the correct corresponding keys.
Here's a piece of code, originally by SKAN, which I've modified for testing purposes - maybe you'll find something useful in there:

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

robodesign
Posts: 131
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

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

08 Oct 2017, 09:24

Hello, guys!

I made a new version. This include support for about 35-40 keyboard layouts, or more, if we include variants.

It has automatic detection at start or continously, as you choose, or when you press a button/shortcut.

Source at: http://p.ahkscript.org/?p=daa02b61

; AVAILABLE SHORTCUTS:
; Ctrl+Alt+Shift+F8 - Toggles "Show single key" option. Useful when you must reliably use dead keys.
; Ctrl+Alt+Shift+F9 - Toggles between two OSD offsets: GuiYa and GuiYb.
; Ctrl+Alt+Shift+F10 - Toggles personal/regional keys support.
; Ctrl+Alt+Shift+F11 - Detect keyboard language.
; Ctrl+Alt+Shift+F12 - Reinitialize OSD. Useful when it no longer appears on top. To have it appear on top of elevated apps, run it in administrator mode.
;
; FEATURES:
; - Show previously pressed key if fired quickly.
; - Count key presses or key fires and mouse clicks.
; - Automatic resizing of OSD/HUD or fixed size.
; - Hides automatically when mouse runs over it.
; - Generate beeps for key presses, modifiers, mouse clicks or just when typing with Capslock.
; - Indicators for CapsLock, NumLock and ScrollLock states.
; - Typing mode; shows what you are typing in an expanding text area.
; - Partial dead keys support, option to turn it off; The work-around is only for the English International keyboard layout.
; - Partial support non-English keyboards. 40 keyboard layouts defined.
; - limited automatic detection of keyboard layouts.
; - the user also has the option to define his regional keys.
; - Easy to configure with many options:
; - to toggle features: key beepers, key counting or previous key;
; - to hide modifiers, mouse clicks or single key presses (which disables typing mode);
; - or hide keys that usually get in the way: Left Click and Print Screen [HideAnnoyingKeys];
; - differ between left and right modifiers;
; - OSD/HUD position, size and display time;
; - beep key presses even if keys are not displayed;
; - some settings toggled by shortcuts are stored permanently in an INI file;
;
; CHANGELOG:
; by Marius Sucan (robodesign.ro)
; v2.85 (2017-10-08)
; - minor improvements for the dead keys work-around
; - added support for 40 foreign keyboard layouts
; - automatic detection of keyboard layouts, at start or continously
; - user also can define personal/regional keys in the settings section
; - new keyboard shortcut, to toggle regional keys
; - new setting: to enable or disable system-wide keyboard shortcuts
; - settings toggled by shortcuts are stored permanently in an INI file
; - except for the option of regional keys support
; v2.73 (2017-10-05)
; - improvements for automatic resize calculation

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



Critique and feedback, always welcomed.

I tested it only on Windows 10 x64, which no longer switches keyboards based on apps, only when you want it.

Best regards, Marius.
Last edited by robodesign on 08 Oct 2017, 11:56, edited 1 time in total.
User avatar
Drugwash
Posts: 307
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

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

08 Oct 2017, 10:03

This error comes up at launch, nothing else would work:
20171008180030.png
20171008180030.png (30.13 KiB) Viewed 454 times
robodesign
Posts: 131
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

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

08 Oct 2017, 11:55

remove the quotes from line 811, LangChars_0418 := "„|”|Ă|ă|Â|â|Î|î|Ș|ș|Ț|ț"
. Here it works with them.

I tested it only on Win10. Things are different here. Detection may also be tricky on your system, if it changes language for every app.

I must do some error control :-) .
User avatar
Drugwash
Posts: 307
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

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

08 Oct 2017, 12:30

There is no 'lower doublequote' on RO layout.
My current system is XP-SP3 x86 and the only installed layout is RO; EN is not needed since it's a subset of RO. So there is no app-specific layout change at all.
Also please note the last four chars in the string (Ş|ş|Ţ|ţ) appear as question marks here. You may wanna use a different text editor that does not screw up characters.
Correct string should be LangChars_0418 := """|Ă|ă|Â|â|Î|î|Ş|ş|Ţ|ţ"

Other issues:
- script shows Shift+] when I type [, I'd really like it to show the real character instead of the key combo.
- sometimes it shows Shift+A (which should actually be Shift+a) while other times it just shows capital A (as it always should).
robodesign
Posts: 131
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

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

08 Oct 2017, 13:01

Please read the to-do list. I want to have that implemented as well, hence it is in my to-do.

In Windows 10, Romanian keyboard is different :) ...and I suspect many other languages changed as well.. I will stick to the Win10 keyboard layout which has those special quotes. There are 3 variations for the Romanian layout: inherited, standard and programmers. I chose the standard one.

Top priority is to make it handle/catch errors when trying to bind keys.
User avatar
Drugwash
Posts: 307
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

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

09 Oct 2017, 10:59

The layout that matches the one in Win95 through XP is 'legacy' (or inherited, as you say). There should be a way to distinguish each variant and adjust accordingly.
Good luck!
robodesign
Posts: 131
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

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

09 Oct 2017, 13:31

Hello!

I made it now to catch/handle errors. It should be more efficient at assigning keys. Failures are limited now only to the key that cannot be assigned, no longer all in the same raw fail. It beeps for each key that failed to bind, but that should not worry you if it works :).

Languages are now in an external file. Place it in the same folder with the script. Make sure both files are UTF-8 with BOM.

Drugwash, it should work on WinXP as well, with your kbd layout.

Source at http://p.ahkscript.org/?p=465b53a1
Source of languages file: http://p.ahkscript.org/?p=fe8603b5

; CHANGELOG:
; by Marius Sucan (robodesign.ro)
; v2.87 (2017-10-09)
; - improvements for assigning keys;
; - errors are now managed, it will beep when key bindings fail
; - [new] option to disable audio alerts :)
; - languages are now in an external file
; - new keyboard layouts for Polish, Azerbaijian, Turkmen


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



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



Please read the notes section.

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

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

10 Oct 2017, 08:37

There are improvements and indeed it works better. There is room for more though. :)
Personally I'm a mouse guy, I like buttons, checkboxes, radiobuttons and so on in a nicely designed GUI, when it comes to options. Strangely and amazingly I try to stay away from hotkeys as much as possible because they always interfere with applications (try to type a simple @ in AOL Mail's web interface with a Romanian Legacy keyboard layout, see if you can! That's because @ on RO (legacy) is issued through AltGr+V or Ctrl+Alt+V, while the imbecils at AOL insist on assigning that hotkey to some stupid command and their hotkeys cannot be disabled). Here I right-click the systray icon and I see no Options item so for me this script has no options at all. Editing the script manually is an ugly job. If/when you get some time it would be great if you could build an Options GUI. ;)

There's also one thing that jumped to bite me: spaces appear as underscores (_____) and I personally feel that's wrong. Or maybe it's my layout's fault, because underscores appear as dashes (-----) instead.

Anyway, your efforts are truly appreciated. Keep up the good work! ;)
robodesign
Posts: 131
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

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

10 Oct 2017, 14:52

Hello!

Thank you very much. Today, I actually decided to try to implement a Tray menu with options or a settings window easy to invoke. I have not yet did anything about it yet, I just added it in my to-do list. Today I decided to make more improvements in regards to typing , in general. So, I am still working on it. ;) Spaces are _ (underscore) because they are visible on the OSD, so when you press backspace, you see you deleted the space.

Now, my main priority is to make it show proper signs when using Shift, eg. Shift+0=). I hope to succed in a way it works with various keyboards.

; CHANGELOG:
; by Marius Sucan (robodesign.ro)
; v2.90 (2017-10-10)
; - from now, numpad keys always initiate typing mode
; - modifiers (Ctrl, Shift, Alt, WinKey) and Tab, Insert no longer clear typed input in the OSD, if pressed once, without a combo
; - unified the behaviour of modifiers
; - fixed some counting bugs :)
; - added option to disable PermanentSettings

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



; TO-DO:
; features to implement:
; - after pressing Shift + [letter] if the following key is a single letter, remember the first Shift + [letter]; done
; - when user types single letters, display Shift + (sign or numeric keys) as signs/symbols, eg. Shift + 0, should be displayed as ); done
; - visual mouse clicks done
; - clipboard monitoring done
; - tray menu, with options done
; - show a generic symbol for ignored dead keys; helps to clarify one was pressed;
;
; glitches to fix [by priority]:
; - display previous key for keys pertaining to loop, 95 done
; - [regression since v2.52] show Shift as a modifier, as Ctrl and Alt; Shift should behave as the other two; it is never displayed alone and countable; done
; - [bug, since v1.00] Shift + [numpad] does not work; no idea why
; - [bug] once a key is pressed, counting of key fires is not initiated after the OSD was hidden for a little awhile;
; - make dead keys work better, even detect them ;)
; - automatic resizing of the OSD/GUI is just a silly hack based on the default font size and the number of typed chars; it often fails to resize properly;
; - redraw issues; it still flickers;
; - make it work reliably with sticky keys; if user presses once Ctrl and another key afterwards, it rarely detects the combination on Winndows 7;

Also at http://p.ahkscript.org/?p=8498fb0e

Best regards, Marius
Last edited by robodesign on 29 Oct 2017, 06:27, edited 1 time in total.
User avatar
Drugwash
Posts: 307
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

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

11 Oct 2017, 09:04

Displaying spaces as underscores can be confusing in certain situations. for example, if I type _ __ _ ___ the OSD would display -___--_-_--- which is not in the least similar to the actual characters typed. Can't find a suitable replacement for this issue though.

The modifiers (Shift/Ctrl/Alt/AltGr) should be displayed when pressed, mainly as a proof that the keyboard does function correctly, and when any other keys are pressed the combo - if accepted by the current layout - should replace the single modifier. Yes, this may prove to be tricky but should be the correct way to handle keypresses IMHO.

The OSK (in XP, at least) does detect pressing of Shift and AltGr (on RO layout) and switches key symbols accordingly in its graphic interface. Shift is also visibly displayed as pressed. This could be important at least for users of unreliable keyboards.

Dunno if I already stated this but I feel such kind of script definitely needs a system-wide keyboard/mouse hook similar to a keylogger. I know this falls at best into a grey area but considering all the issues with different layouts and the difficulties in capturing and displaying the key presses I believe it's the only reliable method. Of course, a handy option to temporarily hide the OSD (during typing of passwords or other sensible information) should be implemented (if not already present), but otherwise this script would never get close to perfection if it only relies on assigning hotkeys.

Please, other respectable members of the community share your opinion on this. Thank you.
robodesign
Posts: 131
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

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

11 Oct 2017, 13:10

Hello!

To type passwords, you must toggle Show Single Keys. Ctrl+Alt+Shift+F8 - Toggles "Show single key" option.

Modifers are displayed when activated, except for Shift. I will have it fixed.

I will implement a settings window too.

Today's progresses are minimal. Lots to fiddle with....

Here's the script: http://p.ahkscript.org/?p=a08fb51c

; CHANGELOG:
; by Marius Sucan (robodesign.ro)
; v2.92 (2017-10-11)
; - rolled back the changes for modifier keys; it resulted in many regressions noticeable for those using StickyKeys; I will insist on this :)
; - clipboard monitoring; it displays briefly what text user copied to clipboard
; - fixed bugs related to showing previous keys


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



; TO-DO:
; features to implement:
; - after pressing Shift + [letter] if the following key is a single letter, remember the first Shift + [letter]; done
; - modifiers should not erase typed text from OSD done
; - when user types single letters, display Shift + (sign or numeric keys) as signs/symbols, eg. Shift + 0, should be displayed as ); done
; - visual mouse clicks done
; - tray menu or window with options/settings done
; - show a generic symbol for ignored dead keys; helps to clarify one was pressed;done
;
; glitches to fix [by priority]:
; - [regression since v2.52] show Shift as a modifier, Shift should behave just like the other modifiers; now, it is never displayed alone and countable; done
; - [bug, since v1.00] Shift + [numpad] does not work; no idea why
; - [bug] once a key is pressed, counting of key fires is not initiated after the OSD was hidden for a little awhile; fixed
; - make dead keys work better, even detect them ;) done
; - automatic resizing of the OSD/GUI is just a silly hack based on the default font size and the number of typed chars; it often fails to resize properly; done/much improved
; - redraw issues; it still flickers;
; - make it work reliably with sticky keys; if user presses once Ctrl and another key afterwards, it rarely detects the combination on Winndows 7;


Best regards, Marius
Last edited by robodesign on 16 Nov 2017, 05:31, edited 2 times in total.
ozzii
Posts: 291
Joined: 30 Oct 2013, 06:04

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

12 Oct 2017, 01:58

Thanks Marius for your work...
robodesign
Posts: 131
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
Contact:

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

12 Oct 2017, 07:57

Hello!

Ezzii, my pleasure; if you have any questions or suggestions, please tell me. IWhat is what you desire the most for it? See the to-do list and tell me.

I am doing my best to make it as usable as possible. I use it constantly and I make it such that I like to use it.

Next is... More work on Shift related connundrums and typing, or visual mouse clicks feature.

New version:
; CHANGELOG:
; by Marius Sucan (robodesign.ro)
; v2.93 (2017-10-12)
; - new option: StickyKeys
; - back again, modifiers behave as I want
; - if StickKeys is off, modifiers (Ctrl, Shift, Alt, WinKey) do not clear typed input in the OSD, if pressed once, without a combo
; - if StickyKeys is on, they erase what is written in the OSD, except for Shift, of course

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



Source at: http://p.ahkscript.org/?p=4fab8086

; TO-DO:
; features to implement:
; - after pressing Shift + [letter] if the following key is a single letter, remember the first Shift + [letter]; done
; - when user types single letters, display Shift + (sign or numeric keys) as signs/symbols, eg. Shift + 0, should be displayed as ); done
; - visual mouse clicks and highlighter/locator done
; - tray menu or window with options/settings done
; - text caret locator/highlighter
; - show a generic symbol for ignored dead keys; helps to clarify one was pressed; done
; - window spy, get texts underneath the mouse
;
; glitches to fix [by priority]:
; - [bug, since v1.00] Shift + [numpad] does not work; wrong behaviour when user presses Shift + [numpad]

Best regards, Marius.
Last edited by robodesign on 16 Nov 2017, 05:29, edited 2 times in total.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Diego and 17 guests