1. Cheryl Leftwich
  2. PowerBuilder
  3. Monday, 10 August 2020 00:22 AM UTC

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

Cheryl Leftwich Accepted Answer Pending Moderation
  1. Wednesday, 19 August 2020 23:31 PM UTC
  2. PowerBuilder
  3. # 1

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

Comment
  1. Cheryl Leftwich
  2. Thursday, 20 August 2020 03:17 AM UTC
I have looked a little deeper at the password field, and it is already set up as a single-line-edit, in spite of the field name assigned as mle_password!! It is always interesting to work with code from 20 years ago, so my bad for not looking more closely beforehand.

So my earlier 'solution' to change it to a single-line-edit is worth nothing at this point.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 19 August 2020 03:13 AM UTC
  2. PowerBuilder
  3. # 2

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!

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Monday, 17 August 2020 13:57 PM UTC
  2. PowerBuilder
  3. # 3

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.

Comment
  1. Cheryl Leftwich
  2. Tuesday, 18 August 2020 06:28 AM UTC
Hi John, At present the users see NO message at all re caps lock on from our deployed client code (built using PowerGen and deployed to user PC's via an MSI). However when run from PB or a project type built exe from PB, the default message (non-custom) DOES appear. I have added your suggested code to my test environment and it works perfectly, but was hopeful that there may be another solution, not involving client code changes, which would mimic the non-custom message that I do see via PB.

Our client releases are done only once or twice a year, with months of lead time, so obviously not quickly modified, so we try to find server or other solutions if at all possible.

I am not able to test Miguel's suggestion easily either, since I already see the non-custom message via PB, so am not able to isolate the effect of that potential change.

Cheryl
  1. Helpful
There are no comments made yet.
Cheryl Leftwich Accepted Answer Pending Moderation
  1. Monday, 17 August 2020 00:42 AM UTC
  2. PowerBuilder
  3. # 4

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?

 

Comment
  1. Miguel Leeuwe
  2. Monday, 17 August 2020 09:42 AM UTC
Hi,

We use 2 single line edits to input username and password. On the sle for the password, we have the checkbox "password" checked. This will make windows warn about the capslock being active, but only when control receives focus and the window previously is already open.

In our application, we already set the focus to the password sle in the "open" event of the window. Therefore the window wasn't visible yet when receiving the focus and this caused the warning not to be seen (at least not until you typed in the wrong password, got an error message and the focus went back to the single line edit.).

To solve this, in the pfc_postopen event (or any other event that you launch from the open event with POST), I simply set focus to the username sle and then back to the password. (the username is most of the times already filled in, so that's why we initially set focus on the password.).

I've tested with our executable and it also works.

So I'm thinking maybe you have a similar situation?

regards
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Monday, 10 August 2020 18:46 PM UTC
  2. PowerBuilder
  3. # 5

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

Comment
  1. Cheryl Leftwich
  2. Monday, 17 August 2020 00:52 AM UTC
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?



Cheryl

  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 10 August 2020 03:24 AM UTC
  2. PowerBuilder
  3. # 6

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

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.