sanyang Posted August 13, 2010 Share Posted August 13, 2010 (edited) I'm currently use this to get status of capslock $Cslstt = DllCall("user32.dll","long","GetKeyState","long",0x14) I want to make this checks continuously but when I put it in the loop, the $Cslstt[0] only equals to the first state of Capslock when I run the program (0 or 1). It means even I toggle capslock, the variable is still the same. I'm a noob here, so is there anyone kind enough to explain the reason to me, and tell me how I can correct this? PS: When I put it in a loop, the capslock LED toggles like crazy. Edited August 13, 2010 by sanyang Link to comment Share on other sites More sharing options...
Yashied Posted August 13, 2010 Share Posted August 13, 2010 $pState = _GetCapsLockState() While 1 $nState = _GetCapsLockState() If $nState <> $pState Then ConsoleWrite('CAPSLOCK: ' & $nState & @CR) $pState = $nState EndIf Sleep(100) WEnd Func _GetCapsLockState() Local $Ret = DllCall('user32.dll', 'int', 'GetKeyState', 'int', 0x14) If @error Then Return SetError(1, 0, 0) EndIf Return BitAND($Ret[0], 1) EndFunc ;==>_GetCapsLockState My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
sanyang Posted August 13, 2010 Author Share Posted August 13, 2010 (edited) Sorry for troubling everyone. I find the way. Just return the variable. :| Thanks Yashied anyways. Edited August 13, 2010 by sanyang Link to comment Share on other sites More sharing options...
nolongthin Posted July 26, 2013 Share Posted July 26, 2013 @Yashied, Thanks for your code but am trying to do this if its on it writes capslock on, and if off it writes capslock off : $pState = _GetCapsLockState() $caps = caps() Func caps() if $pState = 1 then ConsoleWrite("{CAPSLOCK ON}") ;CAPSLOCK Else ConsoleWrite("{CAPSLOCK OFF}") ;CAPSLOCK EndIf EndFunc While 1 $nState = _GetCapsLockState() $caps = caps() ;If $nState <> $pState Then ; ConsoleWrite('CAPSLOCK: ' & $nState & @CR) $pState = $nState ; EndIf Sleep(100) WEnd Func _GetCapsLockState() Local $Ret = DllCall('user32.dll', 'int', 'GetKeyState', 'int', 0x14) If @error Then Return SetError(1, 0, 0) EndIf Return BitAND($Ret[0], 1) EndFunc ;==>_GetCapsLockState I keep getting this >"H:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "H:\personal key\v4\test\tes.au3" {CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF}{CAPSLOCK OFF} >Process failed to respond; forcing abrupt termination... >Exit code: 1 Time: 4.339 Please help i want it to show like this: >"H:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "H:\personal key\v4\test\tes.au3" {CAPSLOCK OFF} {CAPSLOCK ON} >Process failed to respond; forcing abrupt termination... >Exit code: 1 Time: 4.339 Thanks Link to comment Share on other sites More sharing options...
martin Posted July 28, 2013 Share Posted July 28, 2013 I think your code works, but it would be easier to see if you only printed when the casps lock state changed. Something like this $lastState = -1 $pState = _GetCapsLockState() caps() While 1 $pState = _GetCapsLockState() caps() Sleep(100) WEnd Func _GetCapsLockState() Local $Ret = DllCall('user32.dll', 'int', 'GetKeyState', 'int', 0x14) If @error Then Return SetError(1, 0, 0) EndIf Return BitAND($Ret[0], 1) EndFunc ;==>_GetCapsLockState Func caps() If $pState = $lastState Then Return If $pState = 1 Then ConsoleWrite("{CAPSLOCK ON}" & @CR) ;CAPSLOCK Else ConsoleWrite("{CAPSLOCK OFF}" & @CR) ;CAPSLOCK EndIf $lastState = $pState EndFunc ;==>caps Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now