Jump to content

Caps lock light


Recommended Posts

Hello

How can you know in AutoIT if the CapsLock light is on or off.

With _IsPressed it can only find out if the caps lock button is pressed down or not. I want to know if the light if on or off.

Please help

Use Send function: Set CAPSLOCK (on/off/toggle)

Edited by Andreik
Link to comment
Share on other sites

No. You misunderstood me...

I don't want to know if the user is holding down capslock.

I want to know if the LED on the keyboard is on or off.

I want something like this:

if(_capslocklightison()) Then
Send("A")
Else
Send("a")
Endif

I would like the definition for the _capslocklightison function, or a way to tell if the light is on

Edited by oviradoi
Link to comment
Share on other sites

You need to check toggled state:

MsgBox(0, 'NUMLock On', _IsToggled("90"))
MsgBox(0, 'CAPSLock On', _IsToggled("14"))

Func _IsToggled($sHexKey, $vDLL = 'user32.dll')
    ; $hexKey must be the value of one of the keys.
    ; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.
    Local $a_R = DllCall($vDLL, "short", "GetKeyState", "int", '0x' & $sHexKey)
    If Not @error And BitAND($a_R[0], 0xFF) = 1 Then Return 1
    Return 0
EndFunc   ;==>_IsToggled
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

You need to check toggled state:

MsgBox(0, 'NUMLock On', _IsToggled("90"))
MsgBox(0, 'CAPSLock On', _IsToggled("14"))

Func _IsToggled($sHexKey, $vDLL = 'user32.dll')
    ; $hexKey must be the value of one of the keys.
    ; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.
    Local $a_R = DllCall($vDLL, "short", "GetKeyState", "int", '0x' & $sHexKey)
    If Not @error And BitAND($a_R[0], 0xFF) = 1 Then Return 1
    Return 0
EndFunc   ;==>_IsToggled
CAPSLock muttley

MsgBox(0, 'CAPSLock On', _IsToggled("14"))

Func _IsToggled($sHexKey, $vDLL = 'user32.dll')
  ; $hexKey must be the value of one of the keys.
  ; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.
    Local $a_R = DllCall($vDLL, "short", "GetKeyState", "int", '0x' & $sHexKey)
    If Not @error And BitAND($a_R[0], 0xFF) = 1 Then Return 1
    Return 0
EndFunc ;==>_IsPressed
Edited by Andreik
Link to comment
Share on other sites

  • 5 years later...

to turn off the lights LED numlock in on state (normally numlock is on, lights is not necessary), and on light when numlock is off

make this:

Global $DDD_RAW_TARGET_PATH = 1
Global $DDD_REMOVE_DEFINITION = 2
Global $KEYBOARD_INDICATOR_PARAMETERS="ushort UnitId;ushort LedFlags;"
Global $IOCTL_KEYBOARD_SET_INDICATORS = 720904
Global $IOCTL_KEYBOARD_QUERY_INDICATORS = 720960

; Flags to _KeyboardSetLed
Global $KEYBOARD_LIT = 0
Global $KEYBOARD_UNLIT = 8
Global $KEYBOARD_SCROLL_LED = 1
Global $KEYBOARD_NUM_LED= 2
Global $KEYBOARD_CAPS_LED = 4

; #FUNCTION# ====================================================================================================================
; Name...........: _OpenKeyboard
; Description ...: Opens a handle to the keyboard
; Syntax.........: _OpenKeyboard()
; Parameters ....: None
; Return values .: None
; Author ........: Andreas Karlsson (monoceres)
; Modified.......:
; Remarks .......:
; Related .......: _CloseKeyboard
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _OpenKeyboard()
    Local $KeyboardHandle
    DllCall("Kernel32.dll","int","DefineDosDeviceW","dword",$DDD_RAW_TARGET_PATH,"wstr","Keybd","wstr","\Device\KeyboardClass0")
    $KeyboardHandle = DllCall("Kernel32.dll","hwnd","CreateFile","str","\\.\Keybd","dword",0x40000000,"dword",0,"dword",0,"dword",3,"dword",0,"dword",0)
    $KeyboardHandle=$KeyboardHandle[0]
    Return $KeyboardHandle
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: _KeyboardSetLed
; Description ...: Lits/Unlits specified keyboard leds
; Syntax.........: _KeyboardSetLed($KeyboardHandle,$flags)
; Parameters ....: $KeyboardHandle - Handle to the keyboard previously opened with _OpenKeyboard
;                  $flags - A bitwise OR combination of the keyboard constants defined in the top of the script
; Return values .: The previous lit leds ( use BitAND() to figure out which ones)
; Author ........: Andreas Karlsson (monoceres)
; Modified.......:
; Remarks .......:
; Related .......: _OpenKeyboard
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _KeyboardSetLed($KeyboardHandle,$flags)
    Local $PreviousLedConfig
    $Kernel32=DllOpen("Kernel32.dll")

    $kip=DllStructCreate($KEYBOARD_INDICATOR_PARAMETERS)

    DllCall($Kernel32,"int","DeviceIoControl","hwnd",$KeyboardHandle,"dword",$IOCTL_KEYBOARD_QUERY_INDICATORS,"ptr",0,"dword",0, _
            "ptr",DllStructGetPtr($kip),"dword",DllStructGetSize($kip),"dword*",0,"ptr",0)
    $PreviousLedConfig=DllStructGetData($kip,"LedFlags")
    If BitAND($flags,$KEYBOARD_UNLIT) THen
        If Not BitAND(DllStructGetData($kip,"LedFlags"),$KEYBOARD_NUM_LED) And BitAND($flags,$KEYBOARD_NUM_LED) Then $flags=BitXor($flags,$KEYBOARD_NUM_LED)
        If Not BitAND(DllStructGetData($kip,"LedFlags"),$KEYBOARD_CAPS_LED) And BitAND($flags,$KEYBOARD_CAPS_LED) Then $flags=BitXor($flags,$KEYBOARD_CAPS_LED)
        If Not BitAND(DllStructGetData($kip,"LedFlags"),$KEYBOARD_SCROLL_LED) And BitAND($flags,$KEYBOARD_SCROLL_LED) Then $flags=BitXor($flags,$KEYBOARD_SCROLL_LED)
        $flags=BitXOR($flags,$KEYBOARD_UNLIT)
        DllStructSetData($kip,"LedFlags",BitXOR(DllStructGetData($kip,"LedFlags"),$flags))
    Else
        DllStructSetData($kip,"LedFlags",BitOR(DllStructGetData($kip,"LedFlags"),$flags))
    EndIf
    DllCall($Kernel32,"int","DeviceIoControl","hwnd",$KeyboardHandle,"dword",$IOCTL_KEYBOARD_SET_INDICATORS,"ptr",DllStructGetPtr($kip),"dword",DllStructGetSize($kip), _
            "ptr",0,"dword",0,"dword*",0,"ptr",0)
    DllClose($Kernel32)
    Return $PreviousLedConfig
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: _CloseKeyboard
; Description ...: Closes a handle to the keyboard
; Syntax.........: _CloseKeyboard()
; Parameters ....: None
; Return values .: None
; Author ........: Andreas Karlsson (monoceres)
; Modified.......:
; Remarks .......:
; Related .......: _OpenKeyboard
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _CloseKeyboard($KeyboardHandle)
    DllCall("Kernel32.dll","int","DefineDosDeviceW","dword",$DDD_REMOVE_DEFINITION,"wstr","Keybd","wstr","")
    DllCall("Kernel32.dll","int","CloseHandle","hwnd",$KeyboardHandle)
EndFunc

Func FNUMLOCK()

  $STATE=DllCall('user32.dll','int','GetKeyState','int',0x90)

  If BitAND($STATE[0],1)=0 Then
_KeyboardSetLed($kb,BitOr($KEYBOARD_LIT,$arr[0]))

  Else
  _KeyboardSetLed($kb,BitOr($KEYBOARD_UNLIT,$arr[0]))
  EndIf

 EndFunc

Local $arr[3]=[$KEYBOARD_NUM_LED,$KEYBOARD_CAPS_LED,$KEYBOARD_SCROLL_LED]
$kb=_OpenKeyboard()

$prev=_KeyboardSetLed($kb,BitOR($KEYBOARD_UNLIT,$KEYBOARD_CAPS_LED,$KEYBOARD_NUM_LED,$KEYBOARD_SCROLL_LED))

FNUMLOCK()

; Регистрация комбинаций клавиш

 HotKeySet("{NUMLOCK}","FNUMLOCK")
 ;HotKeySet("{CAPSLOCK}","FCAPSLOCK")

; Бесконечный цикл MessageLoop

 While Sleep(100)
 WEnd
_KeyboardSetLed($kb,$prev)
_CloseKeyboard($kb)
Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Do you think it is sensible to reactivate a 4 years old thread :huh:

The OP has been offline for more than 4 years too.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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