Jump to content

checking numlock and turning it off


Recommended Posts

  • 2 weeks later...
  • 1 month later...

PhilZ's solution will not work. He seems to have missed the fact that its NUMLOCK you are working with and not CAPSLOCK.

Change the provided code to the key you want and try again. And you don't have to bother checking the state. Just set it to off regardless of what it is to begin with.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

For CapsLock key.

#Include <WinAPIEx.au3>

_SetCapsLockState(Not _GetCapsLockState())
Sleep(1000)
_SetCapsLockState(Not _GetCapsLockState())

Func _GetCapsLockState()
    Return BitAND(_WinAPI_GetKeyState(0x14), 1) = 1
EndFunc   ;==>_GetCapsLockState

Func _SetCapsLockState($iState)
    If BitXOR($iState, _GetCapsLockState()) Then
        _WinAPI_keybd_event(0x14, 0)
        _WinAPI_keybd_event(0x14, 2)
    EndIf
EndFunc   ;==>_SetCapsLockState

WinAPIEx.au3

Edited by Yashied
Link to comment
Share on other sites

Post #2 was close but there is a difference between the GetAsyncKeyState and GetKeyState.

This should work fine:

IF _WinAPI_GetKeyState(0x90) Then
    MsgBox(0, "Numlock test", "on")
Else
    MsgBox(0, "Numlock test", "off")
EndIf

Func _WinAPI_GetKeyState($iKey)
    Local $aResult
    $aResult = DllCall("User32.dll", "int", "GetKeyState", "int", $iKey)
    If @error Then Return SetError(@error, 0, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_GetKeyState
Edited by danwilli
Link to comment
Share on other sites

@Yashied

How many times do I have to point out that the OP stated NUMLOCK not CAPSLOCK?

a simple

Send("{NUMLOCK off}") does what he wants with no need to even check the current state. If it's already off then it will stay that way.

If there is a need for checking then he can use your code but he needs the keycode for NUMLOCK which IIRC is 0x90

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

@Yashied

How many times do I have to point out that the OP stated NUMLOCK not CAPSLOCK?

a simple

Send("{NUMLOCK off}") does what he wants with no need to even check the current state. If it's already off then it will stay that way.

If there is a need for checking then he can use your code but he needs the keycode for NUMLOCK which IIRC is 0x90

Just talk touched CapsLock. I try Send(), and that does not work for me. So I showed this code.
Link to comment
Share on other sites

Just talk touched CapsLock. I try Send(), and that does not work for me. So I showed this code.

Read my reply again, amd again and again...

You will notice that there is definitly something different between what the OP asked for and what you gave him. FORGET capslock. It's not part of the question.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Link to comment
Share on other sites

OK. I am not going to "inflate" this topic. You want that I deleted my example?

No I don't. What you still (apparently) didn't notice is you gave him the correct code for the Capslock key and he asked about the NumLock key.

Since I have errors when including your WinAPIEx.au3 file (duplicate function) I just took your excellent

_WinAPI_GetKeyState() function

and copied it into this sample code which does what he asked with checking.

$VKey = 0x90

$sState = _WinAPI_GetKeyState($VKey)
Send("{NUMLOCK off}")
MsgBox(0, "Result", $sState)
Sleep(2000)
If $sState Then Send("{NUMLOCK on}")

Func _WinAPI_GetKeyState($vkCode)

    Local $Ret = DllCall('user32.dll', 'int', 'GetKeyState', 'int', $vkCode)

    If @error Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[0]
EndFunc   ;==>_WinAPI_GetKeyState

danwilli got it right.

EDIT: Spelling

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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