kemyliu 发表于 2014-6-24 09:37:44

帮忙编写_Console_ReadConsoleInput()函数从控制台CMD读取其输入的字符

本帖最后由 kemyliu 于 2014-6-24 16:12 编辑

附P版的Console函数:http://www.autoitx.com/forum.php?mod=viewthread&tid=5913&highlight=CMD
那位大大能仿照写一个_Console_ReadConsoleInput()函数,从控制台CMD读取其输入的字符。#AutoIt3Wrapper_Change2CUI=y

$hStdHandle = _Console_GetStdHandle()
_Console_WriteConsole($hStdHandle, "Test of multi-colors" & @CrLf)
_Console_SetConsoleTextAttribute($hStdHandle, random(1, 77, 1))
_Console_WriteConsole($hStdHandle, "I, am the king of the world...!")
_Console_SetConsoleTextAttribute($hStdHandle, random(1, 77, 1))
_Console_WriteConsole($hStdHandle, "            - Pusofalse" & @CrLf)

Func _Console_GetStdHandle($iStdHandle = -11)
      Local $hStdHandle

      $hStdHandle = DllCall("kernel32.dll", "hWnd", "GetStdHandle", "dword", $iStdHandle)
      Return $hStdHandle
EndFunc ;==>_Console_GetStdHandle()


Func _Console_SetConsoleTextAttribute($hStdHandle, $iColor)
      Local $iResult

      $iResult = DllCall("kernel32.dll", "int", "SetConsoleTextAttribute", _
                        "hWnd", $hStdHandle, "dword", $iColor)
      Return $iResult <> 0
EndFunc ;==>_Console_SetConsoleTextAttribute()


Func _Console_WriteConsole($hStdHandle, $sData = "")
      Local $iResult, $tDataWritten

      $tDataWritten = DllStructCreate("char[" & StringLen($sData) + 1 & "]")
      DllStructSetData($tDataWritten, 1, $sData)

      $iResult = DllCall("kernel32.dll", "int", "WriteConsole", _
                        "hWnd", $hStdHandle, _
                        "ptr", DllStructGetPtr($tDataWritten), _
                        "dword", StringLen($sData), _
                        "dword*", 0, "ptr", 0)
      $tDataWritten = 0
      Return $iResult <> 0
EndFunc ;==>_Console_WriteConsole()

wangms 发表于 2014-6-27 13:56:19

帮你顶一下

wangms 发表于 2014-6-29 13:27:16

帮顶赚钱、、、、、、、、、、、、、、、、、、
页: [1]
查看完整版本: 帮忙编写_Console_ReadConsoleInput()函数从控制台CMD读取其输入的字符