How can I detect if a user has caps lock on their keyboard prior to entry of any data?
I am using PowerBuilder 2017, build 1666, and I still under Windows 8 but will be converting to Windows 10 in the near future.
Thanks Cheryl
How can I detect if a user has caps lock on their keyboard prior to entry of any data?
I am using PowerBuilder 2017, build 1666, and I still under Windows 8 but will be converting to Windows 10 in the near future.
Thanks Cheryl
Hi again John,
Sorry I didn't give you all the details you were looking for, so hopefully I can remedy that.
Existing code uses a multi-line edit field for the password, and yes, the password property is checked.
My new code adds a check on the getfocus event for the password field, and using your suggested function, issues a custom message if the caps lock on is detected - as I mentioned, it works perfectly.
From your reply, I now suspect the problem is the use of the multi-line-edit instead of the single-line-edit for the password. This field has not been changed at all, and my business analyst tells me that the windows message used to work in the past, but possibly not since it was the SAP product.
Unfortunately I am not able to test the exe the way the users use it, our official build and deploy process is not open to developers, so I cannot verify a change to single-line-edit for the password field will give the windows message until time comes for user acceptance testing (and to give you some idea of our timeframes, I am working on these and other changes for a release around April 2021)
Many thanks for your help,
Cheryl
Cheryl - Since you seem reluctant to provide any details about how you are issuing a message to the user or info about the input mechanism being used to obtain the password value, I am not able to provide you with any ideas on how to determine why it works when run from the PB IDE and not from the compiled application. Since you have only described what you want in very generic terms, I can only provide you with very generic advice.
If the login window uses a Single-Line-Edit control as the input mechanism for the password and the "Password" property of the SLE is checked, Windows will automatically (but briefly) display the Caps Lock tooltip message shown in Chris' screenshot, but only when the user clicks or tabs into the password SLE. I cannot speak for how this works in Windows 8/8.1, but it does work this way in both Windows 7 and 10. This is accomplished without any "front-end" code, but only if you use a Single-Line-Edit control.
However, if you are instead using a DataWindow to obtain the password from the user, you do NOT get this Windows-managed behavior. You can use the PB tooltip-related properties for a column object in a DW, but you need a way to check the CapsLock key state and enable the tooltip if CapsLock is toggled on. The free framework that Chris provides uses the Timer event in the window to check the CapsLock key state. Miguel uses the GetFocus event. There may be other ways as well.
Best Wishes and Good luck!
Without knowing more about how you are notifying the user that CapsLock is on, it's extremely difficult to provide you with any suggestions or recommendations. Can you supply more information, or code, or screen shot(s)?
I'm also struggling to understand what you mean by "instead of having to change front-end code". Maybe I need another cup of coffee this morning? The code sample I provided detects CapsLock status when it is called, but the actual calling of the function and the means of notifying the user has been left to you because there is more than one way to code an application login window.
Miguel's suggestion is simple to implement and should do the trick, but, without more info on what you've done to this point, there's no way to be certain.
Thanks so much for the solution, it is working beautifully.
Just a follow-up on this. I could not reproduce the problem initially as I was testing from PowerBuilder, but after discussion with our business analyst, it appears that the users do not see the windows caps lock on message that I see from PB - in other words, once the exe is built and deployed, users do not see the message, hence the necessity of coding a message.
I am wondering if there is another way to enable the users to see the caps lock on message from windows, instead of having to change front-end code?
You'll need to call a Windows API function to get this information. Here's the external function declaration:
FUNCTION UnsignedInt GetKeyState ( Long nVirtKey ) LIBRARY "user32.dll"
Here's code for an object function that calls that Windows API:
// Object function declaration:
// Function of_IsCapsLockOn() returns Boolean
//
// Assumes the WinAPI external function declaration is in same object.
UnsignedInt lui_virtualkeystate
Constant Long VK_CAPSLOCK = 20
lui_virtualkeystate = GetKeyState(VK_CAPSLOCK)
// Low-order bit is 1 when the Caps Lock key is toggled on.
If Mod(lui_virtualkeystate,2) = 1 Then
Return True
End If
Return False
The "magic" value 20 is the Windows Virtual Key code for the Caps Lock key. The Windows API actually names this value VK_CAPITAL, by the way.
Using this function, you can enable a tooltip (as Chris' framework does), issue a message or whatever else you decide needs to be done.
HTH, John
Hi Cheryl;
Have a look at my STD Framework's "of_getKeyState" method of the "wn_logon_master" ancestor class.
Check out the OrderEntry "demo" App built from the framework ....
https://sourceforge.net/projects/stdfndclass/files/Applications/PowerBuilder/OrderEntry/
HTH
Regards ... Chris
So my earlier 'solution' to change it to a single-line-edit is worth nothing at this point.