Jump to content

Recommended Posts

Posted

Hi,

New to this forum. I have a problem in that if Caps Lock is on, when I send commands to a particular GUI, the {ENTER} commands are being ignored, meaning my script fails. If I manually switch the Caps lock off, the script works great. I have used the following:

#include <Constants2.au3>

#include <Misc.au3>

If _GetScrollLock() = 1 Then Send("{SCROLLLOCK Toggle}"); 0 = Off / 1 = On

Func _GetScrollLock(); Checks to see if Scroll Lock is on

Local $ret

$ret = DllCall("user32.dll","long","GetKeyState","long",$VK_SCROLL)

Return $ret[0]

EndFunc

If _GetNumLock() = 1 Then Send("{NUMLOCK Toggle}"); 0 = Off / 1 = On

Func _GetNumLock(); Checks to see if Scroll Lock is on

Local $ret

$ret = DllCall("user32.dll","long","GetKeyState","long",$VK_NUMLOCK)

Return $ret[0]

EndFunc

If _GetCapsLock() = 1 Then Send("{CAPSLOCK Toggle}"); 0 = Off / 1 = On

Func _GetCapsLock(); Checks to see if Scroll Lock is on

Local $ret

$ret = DllCall("user32.dll","long","GetKeyState","long",$VK_CAPITAL)

Return $ret[0]

EndFunc

I looked in the Include folder for the VK declarations and none existed for VK_SCROLL, VK_CAPITAL or VK_NUMLOCK, so I created the following in Constants2.au3 (wouldn't let me create them in Constants.au3)

Global Const $VK_SCROLL = 0x91

Global Const $VK_NUMLOCK = 0x90

Global Const $VK_CAPITAL = 0x14

When I run the script, the Number lock and Scroll lock work perfectly, but Caps lock does not switch off. I ran a code scanner to interrogate the Caps lock key and know that it is definitely 0X14, so my script is correct.

Has anyone else managed to resolve this problem????

Posted

That strange, just the Send("{CAPSLOCK Toggle}") doesnt working itself... and BTW, you can use one function to check all 3 keys :)

Global Const $VK_SCROLL = 0x91
Global Const $VK_NUMLOCK = 0x90
Global Const $VK_CAPITAL = 0x14

If _Key_Is_On($VK_SCROLL) Then Send("{SCROLLLOCK Toggle}")
If _Key_Is_On($VK_NUMLOCK) Then Send("{NUMLOCK Toggle}")
If _Key_Is_On($VK_CAPITAL) Then Send("{CAPSLOCK Toggle}")

Func _Key_Is_On($nVK_KEY, $vDLL = 'User32.dll')
    Local $a_Ret = DllCall($vDLL, "short", "GetKeyState", "int", $nVK_KEY)
    
    Return Not @error And BitAND($a_Ret[0], 0xFF) = 1
EndFunc

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

But this seems to work fine:

Opt("SendCapslockMode", 0)

Global Const $VK_SCROLL = 0x91
Global Const $VK_NUMLOCK = 0x90
Global Const $VK_CAPITAL = 0x14

If _Key_Is_On($VK_SCROLL) Then Send("{SCROLLLOCK Toggle}")
If _Key_Is_On($VK_NUMLOCK) Then Send("{NUMLOCK Toggle}")
If _Key_Is_On($VK_CAPITAL) Then Send("{CAPSLOCK Toggle}")

Func _Key_Is_On($nVK_KEY, $vDLL = 'User32.dll')
    Local $a_Ret = DllCall($vDLL, "short", "GetKeyState", "int", $nVK_KEY)
    
    Return Not @error And BitAND($a_Ret[0], 0xFF) = 1
EndFunc

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...