cancel
Showing results for 
Search instead for 
Did you mean: 

Help Writing a Code Stage to Detect State of CapsLock and Then Set CapsLock On/Off

AaronLawrence1
Level 3
Hello,

I'm working with older terminal software. The user interface was built using BASIC and it only accepts normal user entry in CAPS. During testing and development we would have the CapsLock key engaged. However, this means if a developer forgets to disengage the CapsLock any future runs from that machine will cause the Global Send Keys we are using to interface with the terminal to flip the case of the inputs. Mostly this causes a failure when attempting to login to the terminal software (because passwords require lower and upper case).

Using Upper and Lower functions on a Global SendKeys does not solve the problem.

So I'd like to run a code stage at the start of a process to turn off the CapsLock key if it is on.

something like this:
If Get CapsLock = On Then
 Set CapsLock = Off

Because doing a generic SendKeys CAPSLOCK will just toggle it. Off to On or On to Off. Which will cause the issue I'm preventing in the opposite case where the CapsLock was not forgotten.

Thank you,

------------------------------
Aaron Lawrence
Finance Systems Analyst III
Ferguson Enterprises
America
------------------------------
4 REPLIES 4

GopalBhaire
Level 10
Add a page to your Utility - Environment and in code stage add following where IsCaps is a flag output
IsCaps= Control.IsKeyLocked(Keys.CapsLock)​


------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------

Thank you for the quick reply!

So now that I can test the status of the CapsLock, how do I toggle the CapsLock in code?
Also I should note that one of my statements was incorrect, "Because doing a generic SendKeys CAPSLOCK will just toggle it. Off to On or On to Off."

SendKeys "{CAPSLOCK}" only temporarily engages the CapsLock for the duration of the the single call of the SendKeys statement.

I want to turn off the CapsLock if I detect it on at the beginning of a process.

Thank you again,


------------------------------
Aaron Lawrence
Finance Systems Analyst III
Ferguson Enterprises
America/New_York
------------------------------

In an effort to not be that guy on the internet who figured something out and then doesn't share.

Here is the additional code page that I added to the VBO Utility - Environment in addition to the wonderful suggestion by Gopal Bhaire.

Press CapsLock Key

'Simulate Key Press
keybd_event(VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0)
'Simulate Key Release
keybd_event(VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)

That also requires one to add this code to the Global Code in Utility - Environment:

Private Declare Sub keybd_event Lib "user32"  ( ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer )

Private Const VK_CAPITAL As Integer = &H14   
Private Const KEYEVENTF_EXTENDEDKEY As Integer = &H1   
Private Const KEYEVENTF_KEYUP As Integer = &H2

And to add these external references and namespaces:

System.Runtime.dll
System.Runtime.InteropServices


------------------------------
Aaron Lawrence
Finance Systems Analyst III
Ferguson Enterprises
America/New_York
------------------------------

Thanks a lot both @Aaron Lawrence and @GopalBhaire​​, just to let you know I have used both solutions and together they work like magic!

------------------------------
Marco Ramos
Senior Automation Developer
KPMG Malta
Pieta
------------------------------