Sign in to follow this  
Followers 0
Micha1405

For Keyboards Without Leds For Locks

5 posts in this topic

If your keyboard have no leds to show status of numlock, Capslock and Scrolllock !

#include <GUIConstants.au3>
#include <Constants.au3>
Opt("TrayIconHide", 1) 
Global Const $VK_NUMLOCK = 0x90
Global Const $VK_SCROLL = 0x91
Global Const $VK_CAPITAL = 0x14
dim $x,$y
$Apps="Keylocks"
$Off=0x999999
$On=0x00ff00
_getWindowPos()
$mainGui=GUICreate($Apps,100,48,$x,$y,BitOR($WS_OVERLAPPED,$WS_SYSMENU),BitOR($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW))
$label1=GUICtrlCreateLabel("Num",3,10)
$labelNum=GUICtrlCreateLabel(" ",5,0,15,8,$SS_SUNKEN)
$labelCaps=GUICtrlCreateLabel(" ",35,0,15,8,$SS_SUNKEN)
$label2=GUICtrlCreateLabel("Caps",33,10)
$labelScroll=GUICtrlCreateLabel(" ",65,0,15,8,$SS_SUNKEN)
$label3=GUICtrlCreateLabel("Scroll",63,10)

_main()

Func _main()
GUISetState(@SW_SHOW)
;GUICtrlSetState($Apps,$GUI_disable) 
While 1
    $msg = GUIGetMsg()
        Select 
            case $msg=$GUI_EVENT_CLOSE
            _saveWindowPos()    
        ExitLoop
    EndSelect
_toggleKeys()
sleep(10)
WEnd
exit
EndFunc

Func _toggleKeys()
    
if _getNumLock() =0 then
GUICtrlSetBkColor($labelNum,$Off)
Else
GUICtrlSetBkColor($labelNum,$on)
EndIf
if _GetScrollLock() =0 Then
GUICtrlSetBkColor($labelScroll,$Off)
Else
GUICtrlSetBkColor($labelScroll,$on)
EndIf
if _GetCapsLock() =0 Then
GUICtrlSetBkColor($labelCaps,$Off)
Else
GUICtrlSetBkColor($labelCaps,$on)
EndIf

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

func _saveWindowPos()
$pos=WinGetPos ( $Apps )
if not @error Then
    IniWrite(@ScriptDir&"\Keylocks.ini","Position","x",$pos[0])
    IniWrite(@ScriptDir&"\Keylocks.ini","Position","y",$pos[1])
EndIf
EndFunc
Func _getWindowPos()
    $x=IniRead(@ScriptDir&"\Keylocks.ini","Position","x",@DesktopWidth -100)
    $y=IniRead(@ScriptDir&"\Keylocks.ini","Position","y",@DesktopHeight-80)
EndFunc

Share this post


Link to post
Share on other sites



that is very slick!


My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites

cute!

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

I know this is only 6 years late ...

I needed a small utility that can quickly tell if the caps, num and scroll lock keys were on. I decided to modify Micha1405's code, rather than start from the ground up.

I didn't want the GUI to always be visible, but it needed to be easily found. Therefore, here is my modified version of his program.

The major changes are:

- The GUI is not immediately visible.

- Tray icon is re-enabled.

- Hovering over the icon shows a quick tool-tip of the key states.

- Left-click and hold on the icon pops up the GUI.

- Right-click allows the program to be terminated.

;Original code by Micha1405 (http://www.autoitscript.com/forum/topic/25459-for-keyboards-without-leds-for-locks)
;Modified by SlowCoder 05/16/2012
;Main modifications:
;- GUI is hidden on startup.
;- Tray icon is re-enabled.
;- Hovering over the icon shows a quick tool-tip of the key states.
;- Left-click and hold on the icon brings up the GUI.
;- Right-click allows the program to be terminated.
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
opt("TrayMenuMode",1)
Global Const $VK_NUMLOCK = 0x90
Global Const $VK_SCROLL = 0x91
Global Const $VK_CAPITAL = 0x14
$Apps="KeyStat"
$Off=0x999999
$On=0x00ff00
$x = @DesktopWidth - 100
$y = @DesktopHeight - 100
$mainGui=GUICreate($Apps,100,48,$x,$y,BitOR($WS_OVERLAPPED,$WS_SYSMENU),BitOR($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW))
$label1=GUICtrlCreateLabel("Num",3,10)
$labelNum=GUICtrlCreateLabel(" ",5,0,15,8,$SS_SUNKEN)
$labelCaps=GUICtrlCreateLabel(" ",35,0,15,8,$SS_SUNKEN)
$label2=GUICtrlCreateLabel("Caps",33,10)
$labelScroll=GUICtrlCreateLabel(" ",65,0,15,8,$SS_SUNKEN)
$label3=GUICtrlCreateLabel("Scroll",63,10)
GUISetState(@SW_HIDE)
;set up tray icon menu
$TrayExit = TrayCreateItem("Exit")
TraySetClick (16) ;set so menu only shows when right-clicking
_main()
Func _main()
While 1
  $msg = GUIGetMsg()
  Switch $msg
   case $gui_event_close
    ExitLoop
  EndSwitch
  
  switch TrayGetMsg()
   case $TRAY_EVENT_PRIMARYDOWN
    GUISetState(@sw_show,$mainGui)
   case $TRAY_EVENT_PRIMARYUP
    GUISetState(@sw_hide,$mainGui)
   case $TrayExit
    Exit
  EndSwitch
  _toggleKeys()
  sleep(100)
WEnd
exit
EndFunc
Func _toggleKeys()
$ToolTipText = ""
if _getNumLock() =0 then
  GUICtrlSetBkColor($labelNum,$Off)
  $ToolTipText = "Num=OFF"
  Else
  GUICtrlSetBkColor($labelNum,$on)
  $ToolTipText = "Num=ON"
EndIf
if _GetCapsLock() =0 Then
  GUICtrlSetBkColor($labelCaps,$Off)
  $ToolTipText = $ToolTipText & ",Caps=OFF"
  Else
  GUICtrlSetBkColor($labelCaps,$on)
  $ToolTipText = $ToolTipText & ",Caps=ON"
EndIf
if _GetScrollLock() =0 Then
  GUICtrlSetBkColor($labelScroll,$Off)
  $ToolTipText = $ToolTipText & ",Scroll=OFF"
  Else
  GUICtrlSetBkColor($labelScroll,$on)
  $ToolTipText = $ToolTipText & ",Scroll=ON"
EndIf
;
TraySetToolTip($ToolTipText)
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

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  
Followers 0