Jump to content
Sign in to follow this  
MarioFernando

checking numlock and turning it off

Recommended Posts

MarioFernando

anybody know a script to check whwther the numlock is on!

if its on then turn it off by {numlock off}

i dont know how to check it whether its on or not

:D

Share this post


Link to post
Share on other sites
oMBRa

try this:

#include <WinAPI.au3>
$Toggle = _WinAPI_GetAsyncKeyState(20)
If $Toggle Then
    MsgBox(0, '', 'CapsLock On')
Else
    MsgBox(0, '', 'CapsLock Off')
EndIf

Share this post


Link to post
Share on other sites
MarioFernando

try this:

#include <WinAPI.au3>
$Toggle = _WinAPI_GetAsyncKeyState(20)
If $Toggle Then
    MsgBox(0, '', 'CapsLock On')
Else
    MsgBox(0, '', 'CapsLock Off')
EndIf
dosnt work

:-(

Share this post


Link to post
Share on other sites
PhilZ

Why not just send the {CAPSLOCK off}? The result's the same.

Share this post


Link to post
Share on other sites
GEOSoft

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!"

Share this post


Link to post
Share on other sites
Yashied

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

Share this post


Link to post
Share on other sites
DW1

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

Share this post


Link to post
Share on other sites
GEOSoft

@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!"

Share this post


Link to post
Share on other sites
Yashied

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

Share this post


Link to post
Share on other sites
GEOSoft

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!"

Share this post


Link to post
Share on other sites
Yashied
GEOSoft

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!"

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.