Jump to content

Can't switch off Caps lock


Recommended Posts

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????

Link to comment
Share on other sites

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

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

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

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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