Jump to content

Any chance of blocking NUMLOCK?


Recommended Posts

Hi,

you can biuld a loop to check and set state.

$num = DllCall("user32.dll", "long", "GetKeyState", "long", 0x90)
If $num[0] = 1 Then
    _FunktionActiv()
Else
    _FunktionNotActiv()
EndIf


Func _FunktionActiv()
    MsgBox(0, "A", "NumLock is active!")
EndFunc   ;==>_FunktionActiv

Func _FunktionNotActiv()
    MsgBox(0, "N", "NumLock is NOT active")
EndFunc   ;==>_FunktionNotActiv

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

you can biuld a loop to check and set state.

$num = DllCall("user32.dll", "long", "GetKeyState", "long", 0x90)
If $num[0] = 1 Then
    _FunktionActiv()
Else
    _FunktionNotActiv()
EndIf
Func _FunktionActiv()
    MsgBox(0, "A", "NumLock is active!")
EndFunc   ;==>_FunktionActiv

Func _FunktionNotActiv()
    MsgBox(0, "N", "NumLock is NOT active")
EndFunc   ;==>_FunktionNotActiv

So long,

Mega

Thank you very much, Mega. Would you please explain the DllCall line? "Long" seems to be data type "long int", but why is it used twice? "0x90" stands for the hex code of virtual key, in this case "NUMLOCK", right? BTW what is the code for CAPSLOCK?

My idea is to run a compiled exe that would start running in the background upon user logging in (lett's say, by simple autostart linkage). In a infinite while loop I will put your code checking the status of NUMLOCK and CAPSLOCK, say every 3 seconds, so as not to kill the processor). If the status is "on"/"off" my exe will silently change it using AutoIt SEND function. Is the concept good or not? What do you think? How long SLEEP should I put in the loop so as not to kill the machine? Is 3 seconds ok, or maybe I could shorten it to 0.5 seconds?

Thanks in advance for any comment.

Warmly,Narciso

Link to comment
Share on other sites

Thank you very much, Mega. Would you please explain the DllCall line? "Long" seems to be data type "long int", but why is it used twice? "0x90" stands for the hex code of virtual key, in this case "NUMLOCK", right? BTW what is the code for CAPSLOCK?

My idea is to run a compiled exe that would start running in the background upon user logging in (lett's say, by simple autostart linkage). In a infinite while loop I will put your code checking the status of NUMLOCK and CAPSLOCK, say every 3 seconds, so as not to kill the processor). If the status is "on"/"off" my exe will silently change it using AutoIt SEND function. Is the concept good or not? What do you think? How long SLEEP should I put in the loop so as not to kill the machine? Is 3 seconds ok, or maybe I could shorten it to 0.5 seconds?

Thanks in advance for any comment.

Hi,

you are right. See developer thread dlls to get the concept of DLLCalls in Autoit.

Why do you need this? Nevertheless, you can take a sleep of 200 ms

#include <Misc.au3>

Global $dll = DllOpen("user32.dll")
Global $num = DllCall("user32.dll", "long", "GetKeyState", "long", 0x90) ; NumPad
Global $rollen = DllCall("user32.dll", "long", "GetKeyState", "long", 0x91) ; Rollen
Global $capslock = DllCall("user32.dll", "long", "GetKeyState", "long", 0x14) ; Capslock
Global $tasten[3] = [$num[0], $rollen[0], $capslock[0]]
Global $string[3] = ["NumPad", "Rollen", "CapsLock"]

For $i = 0 To UBound($tasten) - 1
    If $tasten[$i] = 1 Then
        _FunktionWennAktiv($string[$i])
    Else
        _FunktionWennNICHTAktiv($string[$i])
    EndIf
Next

Func _FunktionWennAktiv($taste)
    MsgBox(64, "A", $taste & " is active!")
EndFunc   ;==>_FunktionWennAktiv

Func _FunktionWennNICHTAktiv($taste)
    MsgBox(64, "N", $taste & " is NOT active!")
EndFunc   ;==>_FunktionWennNICHTAktiv

While 1
    Sleep(25)
    If _IsPressed("01", $dll) Then ToolTip("Left Mouse", 0, 0, "MouseClick", 1)
    If _IsPressed("02", $dll) Then ToolTip("Right Mouse", 0, 0, "MouseClick", 1)
WEnd
DllClose($dll)

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

you are right. See developer thread dlls to get the concept of DLLCalls in Autoit.

Why do you need this? Nevertheless, you can take a sleep of 200 ms

...

So long,

Mega

Vielen dank noch einmal :) Your code checking the key status works beautiful though I still do not know how to change the status of these "toggle" keys like CAPSLOCK and NUMLOCK :) AutoIt SEND function does not do the job, 'cause it does not change the toggle key status permanently. It actually does send a signal from capslock but the key remains "on". Heh, seems strange to me. Most probably I must use for that task some magic DllCall again, needn't I? Could you help me with that please? I've had a look at MSDN and searched AutoIt forum but in vain... To be honest all this looks scary and too sophisticated for me :]

P.S. Oh, and why I need it - just to avoid problems of accidental putting on the CAPSLOCK or putting off NUMLOCK while working at the computer with a cash register :)

Edited by narciso

Warmly,Narciso

Link to comment
Share on other sites

Hi,

you mean something like this?

Send('{capslock on}')
Send('{capslock off}')
Send('{numlock on}')
Send('{numlock off}')

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

you mean something like this?

Send('{capslock on}')
Send('{capslock off}')
Send('{numlock on}')
Send('{numlock off}')

So long,

Mega

Thank you for the quick answer and not leaving me alone with the problem :) At first, I have just shouted loud "WOW!!!". Unfortunately the code doesn't seem to work for me on my laptop Compaq nc6120 with XP Pro SP2 :)

Send('{capslock on}') makes the capslock status diode flash for a fraction of a second and even the tooltip appears saying "CAPSLOCK ON" but then all is gone and the CAPSLOCK is OFF as before, so actually no effect whatsoever. What is wrong?

Warmly,Narciso

Link to comment
Share on other sites

Hi,

Send('{capslock on}')
Sleep(5000)
Send('{capslock off}')
Sleep(5000)
Send('{numlock on}')
Sleep(5000)
Send('{numlock off}')

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

Send('{capslock on}')
Sleep(5000)
Send('{capslock off}')
Sleep(5000)
Send('{numlock on}')
Sleep(5000)
Send('{numlock off}')

So long,

Mega

Wow, NUMLOCK works just fine!!! I actually still do not know how to physically turn it on on my laptop, nd your code does it!!! :)))) Unfortunately no progress with capslock :) Just a flash of the diode plus tooltip and.. nothing changes???!!! Very strange... Havent tested it on a desktop with standard keybord though... Maybe that's the problem?

Warmly,Narciso

Link to comment
Share on other sites

Wow, NUMLOCK works just fine!!! I actually still do not know how to physically turn it on on my laptop, nd your code does it!!! :)))) Unfortunately no progress with capslock :) Just a flash of the diode plus tooltip and.. nothing changes???!!! Very strange... Havent tested it on a desktop with standard keybord though... Maybe that's the problem?

Hi,

same for me. Maybe it is a bug. I'll have a look for an alternative.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

I tried:

Send('{capslock down}')
Sleep(3000)
Send('{capslock}')
Send('{capslock down}')
Send('{capslock off}')
Send('{capslock up}')

down activates it, but then I cannot deactivate it anymore.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

I tried:

Send('{capslock down}')
Sleep(3000)
Send('{capslock}')
Send('{capslock down}')
Send('{capslock off}')
Send('{capslock up}')

down activates it, but then I cannot deactivate it anymore.

So long,

Mega

Heh, same on my box :) Actually I do need quite the opposite, namely CAPSLOCK OFF in case it has been accidentally pressed. Too bad... Any possibility to use DllCall magic in this problematic case? Thanks for all your help anyway!!! Much appreciated indeed!

Warmly,Narciso

Link to comment
Share on other sites

  • Moderators

Gary had a VB Script I thought he was going to convert that took care of this issue on win 98 (I know it's win xp) but would have probably have taken care of your issue using SetKeyState... or KeySetState (can't remember which it was).... might search around to see if it was ever converted... _GetCapsLock() was one of the functions I remember in that thread (to give you something to search for).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi Ron,

why isn't cpslock working? Do you know more about that issue? Is it already known?

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

Hi Ron,

why isn't cpslock working? Do you know more about that issue? Is it already known?

So long,

Mega

Certain key functions were always an issue on "laptops"/"Win 98" as long as I can remember, I know that jpm worked vigorously to solve a lot of the issues, but I don't know if he ever got to the capslock one.

Here's the thread I remember Gary posting in: http://www.autoitscript.com/forum/index.php?showtopic=38032

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Certain key functions were always an issue on "laptops"/"Win 98" as long as I can remember, I know that jpm worked vigorously to solve a lot of the issues, but I don't know if he ever got to the capslock one.

Here's the thread I remember Gary posting in: http://www.autoitscript.com/forum/index.php?showtopic=38032

Hi,

yeah I read that thread already. Maybe somebody should post it in "Bug Forum" so that some smart guys can think about a solution again. :)

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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