Jump to content
Sign in to follow this  

_GetLockKeyState udf

Recommended Posts


Since a lot of people seem to be experiencing problems with "Send", "ControlSend" and various configurations of "SendCapslockMode" I thought I would whip up a little udf to check the state of the lock keys and then we can set it to what we need it to be, do our send(s) and then restore it. I know "SendCapslockMode" option is supposed to be able to do this, but I still have (intermittent) problems, even with setting the "SendAttachMode" option.

I know that having this return 0 on an error is not such a good idea (since it also returns 0 for OFF, but I wanted a simple Synatx for checking the state: ie: "If GetLockKeyState("caps") then ..." . If anybody has any ideas on how to make this better, please go right ahead. Thanks

; AutoIt Version:   3.2.49
; Description:    Returns the state of the specified "lock key":
;                 CapsLock, ScrollLock, or Numlock
; Syntax:         _GetLockKeyState($sLockKey)
; Parameter(s):  $sLockKey = The "lock" key to check the state of:
;                 in the format "CAPS" or "SCROLL" or NUM" (case insensitive)
; Requirement(s):   None
; Return Value(s):  On Success - Returns an integer representation of the
;                   lock key's state, 1 being "ON", 0 being "OFF", and
;                   sets @ERROR = 0
;                   On Failure - Returns 0 and  sets
;                    @ERROR = 1 if $sLockKey is not valid parameter
;                    @ERROR = 2 if DllCall fails for some reason
; Author(s):       ResNullius based on th.meger
; Note(s):           based on routine posted by th.meger in this thread:
;             http://www.autoitscript.com/forum/index.php?s=&showtopic=39681&view=findpost&p=295635
; Version :        1.0
;Uncomment next two lines for example
;$LockState = _GetLockKeyState("caps")
;If $LockState And Not @error Then MsgBox(4096, "_GetLockKeyState", "Lockstate is: " & $LockState & @CRLF & "@error: " & @error)


Func _GetLockKeyState($lLockKey)
  Local $lGetKey, $lLockKeyState
  Switch StringUpper($lLockKey)
    Case "CAPS"
      $lGetKey = 0x14
    Case "NUM"
      $lGetKey = 0x90
    Case "SCROLL"
      $lGetKey = 0x91
    Case Else
      ;MsgBox(16+4096,"CALL ERROR","Call to _GetLockKeyState() failed with" & @CRLF & CHR(34) & $lLockKey & CHR(34) & "... unrecognized parameter")
      Return 0
  Local $lLockKeyState = DllCall("user32.dll", "long", "GetKeyState", "long", $lGetKey) ; Capslock
  If Not @error Then
    Return $lLockKeyState[0]
    Return 0
EndFunc   ;==>_GetLockKeyState

Share this post

Link to post
Share on other sites

DOH! Now why couldn't I find that when I was searching... :rolleyes: As Gilda (as Emily) used to say: "Nevermind..."

Edit: If anybody wants me, I'll be working ont the next great thing: it's round and goes on the bottom of things to help move them. I haven't worked out all the details yet, but I've come up with a working name: I'm going to call it the "wheel". Whaddya think? :rambo:

Edited by ResNullius

Share this post

Link to post
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
Sign in to follow this