Jump to content
Sign in to follow this  
oshaker

CAPS NUM SCROLL states in tray?

Recommended Posts

oshaker

I am looking for a script that shows me the states of CAPS, Num and SCROLL keys states whether on or off in the tray.

Share this post


Link to post
Share on other sites
Melba23

oshaker,

Where have you looked? A quick search will give you some code to determine the state of the LOCK keys (I know because I have just looked myself ;-)). Then you will need to design some icons (you will, of course, need 8 to cover all possibilities) and use the #AutoIt3Wrapper_Res_Icon_Add directive to load them into your compiled script. Finally, you will need to run a loop to determine the current LOCK state and then display the correct icon using TraySetIcon.

Give it a go yourself - we are here if you run into problems.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
oshaker

#cs ----------------------------------------------------------------------------
A system tray util to indicate the state of the Caps Lock, Num Lock & Scroll Lock Keys
by changing the Icon to suit
#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <Constants.au3>

$close = TrayCreateItem ("Exit") ;incase u wanted to close the app

Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 1)


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

$Apps="KeyState 1.0"

;~ CHANGE THIS PATH TO SUIT  YOUR ENVIRONMENT
FileInstall(".\0.ico",@ScriptDir & "\" )
FileInstall(".\1.ico",@ScriptDir & "\" )
FileInstall(".\2.ico",@ScriptDir & "\" )
FileInstall(".\3.ico",@ScriptDir & "\" )
FileInstall(".\4.ico",@ScriptDir & "\" )
FileInstall(".\5.ico",@ScriptDir & "\" )
FileInstall(".\6.ico",@ScriptDir & "\" )
FileInstall(".\7.ico",@ScriptDir & "\" )

main()

Func main()

While 1
    $msg = TrayGetMsg ()
    Select
        Case $msg = $close
        Exit
    EndSelect
    toggleKeys()
    sleep(100)
WEnd
exit
EndFunc

Func toggleKeys()
    $keystate=0 
If getNumLock() <> 0 then
    $keystate= $keystate  + 1
EndIf

If GetScrollLock() <>0 Then
    $keystate= $keystate  + 2
EndIf

If GetCapsLock() <>0 Then
    $keystate= $keystate  + 4
EndIf

Select 
    Case $keystate = 1
        TraySetIcon("1.ico")
    Case $keystate = 2
        TraySetIcon("2.ico")
    Case $keystate = 3
        TraySetIcon("3.ico")
    Case $keystate = 4
        TraySetIcon("4.ico")
    Case $keystate = 5
        TraySetIcon("5.ico")
    Case $keystate = 6
        TraySetIcon("6.ico")
    Case $keystate = 7
        TraySetIcon("7.ico")
    Case Else
        TraySetIcon("0.ico")
EndSelect

EndFunc

;Code from gafrost ==> http://www.autoitscript.com/forum/index.php?showtopic=12056
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 GetCapsLock()
    Local $ret
    $ret = DllCall("user32.dll","long","GetKeyState","long",$VK_CAPITAL)
    Return $ret[0]
EndFunc

I will try to use #AutoIt3Wrapper_Res_Icon_Add as I need to see if this has to exract icons as with FileInstall

Thanks

Share this post


Link to post
Share on other sites
Melba23

oshaker,

You need the full SciTE4AutoIt3 intallation to use the #AutoIt3Wrapper_Res_Icon_Add directive. It is much easier to use than FileInstall because you merely need set the TraySetIcon parameters as follows:

filename: @ScriptFullPath

iconID: -5 for the first added icon, then -6 and so on (this is because the indices are negative ordinals [do not ask me why!] and the first 5 are the standard Autoit icons)

No messy writing to file needed - the icons are within the complied .exe! Other than that it looks like you are well on your way.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
oshaker

oshaker,

You need the full SciTE4AutoIt3 intallation to use the #AutoIt3Wrapper_Res_Icon_Add directive. It is much easier to use than FileInstall because you merely need set the TraySetIcon parameters as follows:

filename: @ScriptFullPath

iconID: -5 for the first added icon, then -6 and so on (this is because the indices are negative ordinals [do not ask me why!] and the first 5 are the standard Autoit icons)

No messy writing to file needed - the icons are within the complied .exe! Other than that it looks like you are well on your way.

M23

This is not my script, I could have written one, but icons were something to think about. FileInstall extracts the icons, if you are to distribute your script, you might opt to make it one exe and surprise the user with a bunch of icons ^_^ Any way, thanks for your advice.

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.