找回密码
 加入
搜索
查看: 1585|回复: 4

[AU3基础] input 密码如何先显示明文再变成星号【已解决】

[复制链接]
发表于 2017-10-11 12:07:36 | 显示全部楼层 |阅读模式
本帖最后由 fenhanxue 于 2017-10-15 01:43 编辑
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 214, 109, 562, 216)
$Input1 = GUICtrlCreateInput("", 64, 32, 113, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$Label1 = GUICtrlCreateLabel("密码:", 24, 32, 40, 17,$ES_PASSWORD)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
$Input1 = GUICtrlCreateInput("", 64, 32, 113, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))

这样的样式,键盘打字进去,会直接显示星号

有没办法实现这样的效果:
键盘输入一个字符,这个字符先明文显示在input里,过200毫秒左右时间,再变成星号?
发表于 2017-10-11 16:18:05 | 显示全部楼层
回复 1# fenhanxue


    我記得 INPUT框  有個範例是  限制輸入的字元

因為它採用了  時時檢測的方法  可以 做到  變化一下

檢測完了  就 直接改為* 號  然後 把真正的資料 記在另外的變數裡
 楼主| 发表于 2017-10-11 18:47:49 | 显示全部楼层
回复 2# kk_lee69
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 449, 192, 114)
$Input1 = GUICtrlCreateInput("", 32, 40, 529, 21)
$bt = GUICtrlCreateButton('读',10,100,50,40)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $data = ''

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $bt
                        MsgBox(0,'',$data)
                        

        EndSwitch
        
        check();
WEnd


Func check();
        Local $temp = GUICtrlRead($Input1)
        Local $len_new = StringLen($temp)
        Local $len_old = StringLen($data)
        
        
        If $len_new > $len_old Then
                Local $temp_right = StringTrimLeft($temp,StringLen($data))
                $data &= $temp_right
                Local $out = ''
                For $i = 1 To StringLen($data)
                        $out &= '*'
                Next
                Sleep(200)
                GUICtrlSetData($Input1,$out)
        ElseIf $len_new < $len_old Then
                $data = StringTrimRight($data,$len_old-$len_new)
        EndIf
EndFunc
这样?
感觉输快了会卡顿
发表于 2017-10-12 11:47:47 | 显示全部楼层
回复 3# fenhanxue

理論上 輸入密碼 不會有人打快的吧   打快了 不就等同 不顯示 一樣的意思

我覺得你的做法效果不錯了
我本來的意思是  如下的範例

從 MY_WM_COMMAND 去改 就好

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
$Form1 = GUICreate("Form1", 629, 106, 192, 132)
$Input1 = GUICtrlCreateInput("Input1", 40, 32, 433, 24)
$Button1 = GUICtrlCreateButton("Button1", 496, 32, 105, 33)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
 
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1                   
                        GUICtrlSetData($Input1, '')
        EndSwitch
WEnd
 
Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
        Local Const $EN_CHANGE = 0x300
        Local $nNotifyCode = BitShift($wParam, 16)
        Local $nID = BitAND($wParam, 0xFFFF)
        Local $hCtrl = $lParam
        If $nID = $Input1 Then
                If $nNotifyCode = $EN_CHANGE Then
                        $read=GUICtrlRead($Input1)
                        If String(StringLeft($read,1))=="0" Or String(StringLeft($read,1))=="." Then
                                        GUICtrlSetData($Input1,StringRegExpReplace($read,'^0+|^\.+',''))
                        Else
                                $write=StringRegExpReplace($read,'[^\.0-9]+','')
                                $temp=StringSplit($write,".",1+2)
                                if UBound($temp)>2 Then $write=$temp[0]&"."&$temp[1]
                                GUICtrlSetData($Input1,$write)
                        EndIf
                EndIf
        EndIf
EndFunc
 楼主| 发表于 2017-10-15 01:43:31 | 显示全部楼层
回复 4# kk_lee69


    恩,还是这样用注册消息靠谱,注册消息这块一直一知半解,感谢指点啦
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-27 05:04 , Processed in 0.074254 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表