Jump to content

Password Reveal On Button/Mouse Down


Recommended Posts

I am so close to getting a password show/reveal button working but not quite there.  This sample works on the second mouse down event. I can't figure out what's going on yet.

 

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <Misc.au3>
Local $hDLL = DllOpen("user32.dll")
$hGUI = GUICreate("Test", 500, 200)
$cInput = GUICtrlCreateInput("", 10, 10, 200, 20, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
$cCheck = GUICtrlCreateButton("Show Password", 10, 50, 150, 20)
GUISetState()


$sDefaultPassChar = GUICtrlSendMsg($cInput, $EM_GETPASSWORDCHAR, 0, 0);Retrieve the ASCII value of the default password char
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cCheck
            While 1
               ConsoleWrite("_IsPressed - Left Mouse was pressed." & @CRLF)
               GUICtrlSendMsg($cInput, $EM_SETPASSWORDCHAR, $sDefaultPassChar, 0)
               GUICtrlSetState($cInput, $GUI_FOCUS)
               While _IsPressed("01", $hDLL) ; Wait until mouse is released.
                     Sleep(20)
               WEnd
               ConsoleWrite("_IsPressed - Left Mouse was released." & @CRLF)
               GUICtrlSendMsg($cInput, $EM_SETPASSWORDCHAR, 0, 0)
               GUICtrlSetState($cInput, $GUI_FOCUS)
               ExitLoop
               Sleep(20)
            WEnd
    EndSwitch
WEnd
DllClose($hDLL)

 

Thanks for any help.

Edited by NassauSky
Link to post
Share on other sites
Posted (edited)

OK for anyone else interested.

Thanks from the pieced together code help from @Yashied@Melba23

 

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <EditConstants.au3>
#include <Misc.au3>
Global $Over = False, $OldOver = False
Local $hDLL = DllOpen("user32.dll")
$Form1 = GUICreate('Form1', 230, 297, 303, 543)
$Button1 = GUICtrlCreateButton('Reveal Password', 80, 100, 75, 25)
$cInput = GUICtrlCreateInput("", 10, 10, 200, 20, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
GUISetState(@SW_SHOW)
$sDefaultPassChar = GUICtrlSendMsg($cInput, $EM_GETPASSWORDCHAR, 0, 0)
$hWnd = ControlGetHandle(WinGetHandle('Form1'), '', '[CLASS:Button; INSTANCE:1]')

While 1
    $tPoint = _WinAPI_GetMousePos()
    If _IsPressed("01", $hDLL) Then
        If Not $Over And _WinAPI_WindowFromPoint($tPoint) = $hWnd Then
            ConsoleWrite('Over' & @CR)
            $Over = 1
            GUICtrlSendMsg($cInput, $EM_SETPASSWORDCHAR, 0, 0)
            GUICtrlSetState($cInput, $GUI_FOCUS)
            ControlClick ( $Form1, "", $cInput, "left"  )

        EndIf
    Else
        If $Over Then
            ConsoleWrite('Lost' & @CR)
            $Over = 0
            GUICtrlSendMsg($cInput, $EM_SETPASSWORDCHAR, $sDefaultPassChar, 0)
            GUICtrlSetState($cInput, $GUI_FOCUS)
            ControlClick ( $Form1, "", $cInput, "left"  )

        EndIf
    EndIf
    $nMsg = GUIGetMsg()

    Switch $nMsg
    Case $GUI_EVENT_CLOSE
            DllClose($hDLL)
            Exit
    EndSwitch
WEnd

 

Edited by NassauSky
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...