Disabling Caps Lock key in Powerbuilder Application

Posted on 2004-04-20
Last Modified: 2013-12-26
I have several datawindows in which users enter data such as names.  I want to prevent them from using the Caps Lock key completely.  I attempted coding for a pbm_dwnkey event.  However, this only works when the user presses the Caps Lock key, not when it is "on".  I have considered annoying them by offering a correction using WordCap() every time a field is entered in all caps.  However, this would likely make some people pretty upset.  So, is this possible?
Question by:QueenKretee
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 15

Expert Comment

ID: 10871301
See links below:
Disabling a Keystroke in A DataWindow Control

Triggering the Print Screen Key and Other Keys Dynamically

LVL 18

Expert Comment

ID: 10875419

why do u want to disable caps lock... i understand u want the user to enter only in lowercase... that case why don't u set the edit properties of all ur column to lowercase (Case option)
Properties---> Edit----> Case .... to 'lower'


Author Comment

ID: 10877000
My users enter a lot of proper names.  Say we had Bob Smith.  I would want it just like this: Bob Smith.  Not bob smith or BOB SMITH.  I have considered using the WordCap() function.  However, then I may run into another problem...I get incorrect results with a name like McDonald.  Any other suggestions Rosh?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 10877026
I see where we're going with the two suggestions that you made.  However, how can I tell when the user has the caps lock key "on"?  The dwnkey event only triggers when the key is pressed, not when the key is already "on".  Is there some other way of determining if caps lock is on or off?
Thank you in advance!
LVL 15

Accepted Solution

namasi_navaretnam earned 500 total points
ID: 10877665
Kristi, Try these functions:

GetKeyboardState( ) & SetKeyboardState( )
The first function returns the present state of every key on the keyboard into an array of 256 integers based on the characters ASCII representation.  The second function sets the keyboard to the state given in the array.  A zero value represents that the key is not pressed.  There is no PowerBuilder equivalent.

Global External Function:
FUNCTION boolean GetKeyboardState(ref integer kbarray[256])  LIBRARY "USER32.DLL"
FUNCTION boolean SetKeyboardState(ref integer kbarray[256]) LIBRARY "USER32.DLL"
Function ulong GetDC(ulong hwnd) library "user32.dll"

//GetKeyboardState( )
boolean rtn
integer ipkey[256]
rtn = GetKeyboardState(ipkey)

//SetKeyboardState( )
rtn = SetKeyboardState(ipkey)
if rtn = false then
 Messagebox("Failed","Something went wrong when loading into array")
 Messagebox("Successful","Keyboard state is loaded back into buffer")
end if

GetKeyState( )
This function returns the present state of a specific key on the keyboard based on that key's ASCII representation.  A zero value represents that the key is not pressed.  There is no PowerBuilder equivalent.

Global External Function:
Function int GetKeyState(integer VirtualKeycode) Library "User32.dll"

int rtn
rtn = GetKeyState(65)  // 65 = A
if rtn = 0 then
 MessageBox("Key State","Letter 'A' not pressed!")
 MessageBox("Key State","Letter 'A'  is pressed!")
end if


Author Comment

ID: 10877981
Thank you very much Namasi.  Great information! Very Helpful.
LVL 15

Expert Comment

ID: 10878263
Glad to help!!!

Namasi Navaretnam

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project ( automates most of the tasks discussed in this article. You can even fin…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question