Jump to content

determing state of capslock, scroll, and numlock


Recommended Posts

If I remember correctly it was possible to retrive the state of at least 2 of

the 'locks in AutoIt v2. However I haven't seen this been done in v3.

It's strange really...

It might be possible with a DLLCall though..

Well, my guessing isn't exactly helping you, so maybe someone

else can do that..? Anyone ? :(

Link to comment
Share on other sites

Return of 0 is off, 1 is on

Global Const $VK_NUMLOCK = 0x90
Global Const $VK_SCROLL = 0x91
Global Const $VK_CAPITAL = 0x14

ConsoleWrite(_GetNumLock() & @LF)
ConsoleWrite(_GetScrollLock() & @LF)
ConsoleWrite(_GetCaps() & @LF)

Func _GetNumLock()
    Local $ret
    $ret = DllCall("user32.dll","long","GetKeyState","long",$VK_NUMLOCK)
    Return $ret[0]
EndFunc

Func _GetScrollLock()
    Local $ret
    $ret = DllCall("user32.dll","long","GetKeyState","long",$VK_SCROLL)
    Return $ret[0]
EndFunc

Func _GetCaps()
    Local $ret
    $ret = DllCall("user32.dll","long","GetKeyState","long",$VK_CAPITAL)
    Return $ret[0]
EndFunc
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Or could be 1 function that returns an array of the 3 key states

Example:

$KeyStates = _GetKeyState()
For $i = 1 to $KeyStates[0]
    ConsoleWrite($KeyStates[$i] & @LF)
Next

Func _GetKeyState()
    Const $VK_NUMLOCK = 0x90
    Const $VK_SCROLL = 0x91
    Const $VK_CAPITAL = 0x14
    Local $ret, $a_keystate[4]
    $a_keystate[0] = 3
    $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_NUMLOCK)
    $a_keystate[1] = $ret[0]
    $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_SCROLL)
    $a_keystate[2] = $ret[0]
    $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_CAPITAL)
    $a_keystate[3] = $ret[0]
    Return $a_keystate
EndFunc  ;==>_GetKeyState

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

gafrost,

Thanks. I could not have figured that out on my own!

How does someone go about learning about DllCall and user32.dll, (or other dlls) etc?

EDIT:

I just tried both versions of the code and got nothing back for the return values. I tried 3.1.1.38 and the .41 betas.

Any ideas?

-John

Edited by jftuga
Link to comment
Share on other sites

Do you use SciTe Editor?

If not change the ConsoleWrite to MsgBox statements

for example:

$KeyStates = _GetKeyState()
For $i = 1 to $KeyStates[0]
    MsgBox(0,"Key State",$KeyStates[$i])
Next

Func _GetKeyState()
    Const $VK_NUMLOCK = 0x90
    Const $VK_SCROLL = 0x91
    Const $VK_CAPITAL = 0x14
    Local $ret, $a_keystate[4]
    $a_keystate[0] = 3
    $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_NUMLOCK)
    $a_keystate[1] = $ret[0]
    $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_SCROLL)
    $a_keystate[2] = $ret[0]
    $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_CAPITAL)
    $a_keystate[3] = $ret[0]
    Return $a_keystate
EndFunc ;==>_GetKeyState
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

using the loop with consolewrite and using the release version of autoit

>Running: (3.1.1.1):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\Gary\My Documents\test5.au3" 

1

0

0

>AutoIT3.exe ended.

>Exit code: 0    Time: 1.077

Also running WinXp SP2

Info from MSDN

Function Information

Minimum DLL Version user32.dll

Header Declared in Winuser.h, include Windows.h

Import library User32.lib

Minimum operating systems Windows 95, Windows NT 3.1

you say $ret isn't returning anything, if you just $ret instead of $ret[0] then you would be correct. Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • 8 years later...
for my self i prefer this code:
Global Const $VK_NUMLOCK = 0x90
Global Const $VK_SCROLL = 0x91
Global Const $VK_CAPITAL = 0x14


Func _LockKeyGetState($KeyHex)
    Local $ret
    $ret = DllCall("user32.dll","long","GetKeyState","long",$KeyHex)
    Return $ret[0]
EndFunc

e. g. numlock:

_LockKeyGetState($VK_NUMLOCK)
or
_LockKeyGetState(0x90)
 
It will return 1 if activated and 0 if not
Link to comment
Share on other sites

almost 9 years old, it is not record setting but still...

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

  • Moderators

Vinzent,

Welcome to the AutoIt forum. :)

Please do not necro-post like this again. We discourage it because Autoit has changed so much since this thread was started that the old code seldom runs any more. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...