找回密码
 加入
搜索
查看: 146|回复: 2

[AU3基础] 【已解决】有什么函数可以把字符串中的大小写字母互换吗?

[复制链接]
发表于 2026-3-22 07:24:04 | 显示全部楼层 |阅读模式
本帖最后由 fybhwsx 于 2026-3-22 09:51 编辑

如:1+dfeBCSD-ssaBB^!Vs
换成:1+DFEbcsd-SSAbb^!vS
只换字母,其它字符不变。

用它https://chat.deepseek.com/解决了,这东西真有点用。哈哈。。

其实我想要实现的是用大写锁定,来解决中文输入法输入英文被干扰无法输入的问题。
deepseek给的函数:
Func CAPSLOCKSwap($zfc)
    Local $sResult = ""
    For $i = 1 To StringLen($zfc)
        Local $char = StringMid($zfc, $i, 1)
        Local $asc = Asc($char)
        If $asc >= 65 And $asc <= 90 Then      ; A-Z
            $sResult &= Chr($asc + 32)          ; 转小写
        ElseIf $asc >= 97 And $asc <= 122 Then  ; a-z
            $sResult &= Chr($asc - 32)          ; 转大写
        Else
            $sResult &= $char                    ; 不变
        EndIf
    Next
    Return $sResult
EndFunc

再自定义_send函数就行了,这下什么中文输入法都不影响输入了吧。
Func _Send($AJ, $BZ = 0)
    Send('{CAPSLOCK on}') ;开启大写锁定
    Send(CAPSLOCKSwap($AJ), $BZ) ;大小写互转输入
    Send('{CAPSLOCK oFF}') ;关闭大写锁定
EndFunc

发表于 2026-3-22 19:37:39 | 显示全部楼层
autoit 有字符串处理函数 不过无法实现你描述的功能,只能挨个字符转换。
Example()

Func Example()
        Local $aArray = StringToASCIIArray("1+dfeBCSD-ssaBB^!Vs")
        For $s = 0 To UBound($aArray) - 1
                If $aArray[$s] > 64 and $aArray[$s] < 91 Then
                        $aArray[$s] += 32
                ElseIf $aArray[$s] > 96 and $aArray[$s] < 123 Then
                        $aArray[$s] -= 32
                EndIf
        Next
        ; 把数组转换成字串.
        Local $sString = StringFromASCIIArray($aArray)
        MsgBox(0, "", $sString)
EndFunc   ;==>Example

评分

参与人数 1金钱 +40 收起 理由
fybhwsx + 40 赞一个!

查看全部评分

发表于 2026-3-22 19:54:31 | 显示全部楼层
实际对创口输出字符串的时候可以直接关闭输入法。不需要做这种转换。

#include <WinAPI.au3>

Opt("SendCapslockMode", 0)

Sleep(500)

Global $Win_MemberActive = WinGetHandle("[CLASS:Notepad]")
WinActivate($Win_MemberActive)
WinAPI_SetKeyboardLayout($Win_MemberActive) ;切换输入法到英文
ControlSend($Win_MemberActive, "", "", "AAbbccDD")

;输入法切换到英文
Func WinAPI_SetKeyboardLayout($hWnd, $iFlags = 0)
        Local $hLocale, $iLanguage
        If @OSVersion = "WIN_10" Then
                $iLanguage = 0xd0000804
        Else
                $iLanguage = 0x00000804
        EndIf

        If Not _WinAPI_IsWindow($hWnd) Then Return SetError(@error + 10, @extended, 0)
        Local $hLocale = 0
        If $iLanguage Then
                $hLocale = _WinAPI_LoadKeyboardLayout($iLanguage, $KLF_SUBSTITUTE_OK)
                If Not $hLocale Then Return SetError(10, 0, 0)
        EndIf

        Local Const $WM_INPUTLANGCHANGEREQUEST = 0x0050
        DllCall('user32.dll', 'none', 'SendMessage', 'hwnd', $hWnd, 'uint', $WM_INPUTLANGCHANGEREQUEST, 'uint', $iFlags, 'uint_ptr', $hLocale)
        If @error Then Return SetError(@error, @extended, 0)
        _WinAPI_ActivateKeyboardLayout($hLocale)
        Return $hLocale
EndFunc   ;==>WinAPI_SetKeyboardLayout

评分

参与人数 1金钱 +40 收起 理由
fybhwsx + 40 赞一个!

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2026-4-15 23:42 , Processed in 0.056999 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

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