grimmlock Posted February 6, 2013 Share Posted February 6, 2013 (edited) Here is my code: expandcollapse popupOpt("TrayOnEventMode",1) Opt("TrayMenuMode",1) Global Const $VK_NUMLOCK = 0x90 Global Const $VK_SCROLL = 0x91 Global Const $VK_CAPITAL = 0x14 While 1 If _GetNumLock() = 1 Then SplashTextOn('', 'NumLock = ON', 150, 50) Sleep(2000) SplashOff() Else Endif Sleep(10) If _GetNumLock() = 0 Then SplashTextOn('', 'NumLock = OFF', 150, 50) Sleep(2000) SplashOff() Else EndIf WEnd 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 IsVisible($handle) If BitAND(WinGetState($handle), 2) Then Return 1 Else Return 0 EndIf EndFunc ;==>IsVisible Func _exit() Exit EndFunc What is happening: when it is running it constantly splashed Num Lock = On or Off. Desired Outcome: Always run in the task bar and only splashText when the status changes. Any ideas? Thanks Grimm Edited February 6, 2013 by grimmlock Thanks Grimm Link to comment Share on other sites More sharing options...
kylomas Posted February 6, 2013 Share Posted February 6, 2013 (edited) grimmlock, If I were doing this I would use a technique like this (code is rough but you get the idea) expandcollapse popup#include <GUIConstantsEx.au3> #AutoIt3Wrapper_Add_Constants=n local Const $VK_NUMLOCK = 0x90 local Const $VK_SCROLL = 0x91 local Const $VK_CAPITAL = 0x14 local $state[3][2] = [[0,0],[0,0],[0,0]], $hit = false adlibregister('checkstate',1000) while 1 if $hit then splashtexton('State Monitor','Num lock ' & $state[0][0] & @crlf & 'Scroll Lock ' & $state[1][0] & @crlf & 'Caps Lock ' & $state[2][0]) $hit = False adlibregister('_splashoff',2000) endif sleep(500) wend Func checkstate() Local $ret $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_NUMLOCK) $state[0][0] = $ret[0] $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_SCROLL) $state[1][0] = $ret[0] $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_CAPITAL) $state[2][0] = $ret[0] for $1 = 0 to ubound($state) - 1 if $state[$1][0] <> $state[$1][1] then $state[$1][1] = not $state[$1][1] $hit = True EndIf next EndFunc func _splashoff() SplashOff() adlibunregister('_splashoff') endfunc kylomas edit: modified code, forgot to unregister adlib Edited February 6, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted February 6, 2013 Share Posted February 6, 2013 This is a little cleaner... expandcollapse popup#include <EditConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #AutoIt3Wrapper_Add_Constants=n HotKeySet("{Esc}", "captureEsc") local $keys[3][4] = [['NUM LOCK','OFF','OFF',0x90],['SCROLL LOCK','OFF','OFF',0x91],['CAPS LOCK','OFF','OFF',0x14]], $hit = false local $state[2] = ['OFF','ON'] local $gui010 = guicreate('',200,75,-1,-1,$ws_popup) local $asize = wingetclientsize($gui010) local $lbl010 = guictrlcreatelabel('',0,0,$asize[0],$asize[1],$es_center) guictrlsetfont(-1,12,800,default,'Arial Black') adlibregister('checkstate',250) while 1 for $1 = 0 to ubound($keys) - 1 if $keys[$1][1] <> $keys[$1][2] then $keys[$1][1] = $keys[$1][2] $hit = True EndIf next if $hit then guictrlsetdata($lbl010,'') for $1 = 0 to ubound($keys) - 1 guictrlsetdata($lbl010,guictrlread($lbl010) & $keys[$1][0] & ' = ' & $keys[$1][1] & @crlf) next guisetstate(@sw_show,$gui010) $hit = False adlibregister('_splashoff',2000) endif SLEEP(100) wend Func checkstate() Local $ret for $1 = 0 to ubound($keys) - 1 $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $keys[$1][3]) if $ret[0] = 0 or $ret[0] = 1 then $keys[$1][2] = $state[$ret[0]] next EndFunc func _splashoff() guisetstate(@sw_hide,$gui010) endfunc Func captureEsc() exit EndFunc kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
guinness Posted February 6, 2013 Share Posted February 6, 2013 I would use WinAPIEx that comes with AutoIt beta or search the Forum. The constants were a lot more readable for me. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
grimmlock Posted February 6, 2013 Author Share Posted February 6, 2013 Thank you Kylomas and guiness for all your help. Grimm Thanks Grimm Link to comment Share on other sites More sharing options...
kylomas Posted February 6, 2013 Share Posted February 6, 2013 I would use WinAPIEx that comes with AutoIt beta or search the Forum. The constants were a lot more readable for me.Grimmlock had the constants originally but I took them out when I created an array. They could jut as easily be put back in. I agree that this is a better coding practice, especially in an example or teaching situation.kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
PhoenixXL Posted February 6, 2013 Share Posted February 6, 2013 You can achieve the same through this #include <GUIConstantsEx.au3> #include <HotString.au3> HotStringSet( "{Caps Lock}", "CheckKey" ) HotStringSet( "{Scroll Lock}", "CheckKey" ) HotStringSet( "{Num Lock}", "CheckKey" ) While 1 Sleep(10) WEnd Func CheckKey() Local $KeyName = StringRegExp( $_HotString_buffer, '({[^{}]+})+', 3 ) $KeyName = $KeyName[0] ConsoleWrite( $KeyName & ": Toggled" & @CR ) EndFunc My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
kylomas Posted February 6, 2013 Share Posted February 6, 2013 (edited) PhoenixXL, If you look at hotstring.au3 you will see that th script is reacting to a "key down", not interrogating the toggle state. kylomas edit: corrected info Edited February 6, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
guinness Posted February 6, 2013 Share Posted February 6, 2013 (edited) Correct me if I'm wrong, but isn't the HotString example only useful if the user types {Caps Lock}? Though I don't want the topic to stray from the original question. Edited February 6, 2013 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
kylomas Posted February 6, 2013 Share Posted February 6, 2013 (edited) No, the regexp takes care of that...edit: corrected answer = Yes, but the regexp takes care of that (...there is an imp in my fingers again...)PhoenixXL is running the SRE against a keyname (text) enclosed in braces (the contents of $_HotString_buffer) Edited February 6, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
PhoenixXL Posted February 7, 2013 Share Posted February 7, 2013 This will help the OP to trigger on KeyUp#include <Misc.au3> #include <HotString.au3> HotStringSet("{Caps Lock}", "CheckKey") HotStringSet("{Scroll Lock}", "CheckKey") HotStringSet("{Num Lock}", "CheckKey") While 1 Sleep(10) WEnd Func CheckKey() Local $KeyName = StringRegExp($_HotString_buffer, '({[^{}]+})+', 3) $KeyName = $KeyName[0] ConsoleWrite($KeyName & ": Toggled" & @CR) Local $Array[3] = ['{Caps Lock}', '{Scroll Lock}', '{Num Lock}'] Local $iIndex For $i = 0 To 2 If $Array[$i] = $KeyName Then $iIndex = $i ExitLoop EndIf Next ClearTillUp($iIndex) EndFunc ;==>CheckKey Func ClearTillUp($iIndex) Local $Array[3] = ["14", "91", "90" ] While _IsPressed( $Array[$iIndex ] ) Sleep(10) WEnd EndFunc ;==>ClearTillUp but isn't the HotString example only useful if the user types {Caps Lock}?No, Its for the Caps Lock key press.. The UDF just checks the lparam with GetKeyNameText and hence caps lock is returned My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
PhoenixXL Posted February 7, 2013 Share Posted February 7, 2013 (edited) I guessed we could do it with the native HotKeySet according to the help fileWhen you set a hotkey, AutoIt captures the key-press and does not pass it on to the active application, with one exception: the Lock keys (NumLock, CapsLock, and ScrollLock) still toggle their respective state!the Key State is toggled that is Caps Lock is On but the character typed is still small Edited February 7, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. 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