Jump to content

Only show once


Recommended Posts

Here is my code:

Opt("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 by grimmlock

Thanks

Grimm

Link to comment
Share on other sites

grimmlock,

If I were doing this I would use a technique like this (code is rough but you get the idea)

#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 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

This is a little cleaner...

#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

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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

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

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

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 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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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

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

I guessed we could do it with the native HotKeySet

according to the help file

When 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 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

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
 Share

  • Recently Browsing   0 members

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