In the following script, I'm trying to use "SetConsoleCursorPosition" (Wrapped in MoveCursor()) to move the cursor around. The problem is, instead of setting the cursor to the correct coordinates, it always moves to 0,0 (Top left corner).
Code:
#Persistent
DllCall("AllocConsole")
hOutput := DllCall("GetStdHandle",UInt,-11)
DllCall("SetConsoleTitle",str,"Slanter's Console")
Write("SetConsoleCursorPosition hates me`n")
GetCursor(X,Y)
MsgBox Cursor is at %X%,%Y%
MoveCursor(2,2) ; Should move the cursor to 2,2
GetCursor(X,Y)
MsgBox Cursor is at %X%,%Y%
; This should be written starting at the second character of the second line. (Showing that GetCursor works correctly)
Write("Blah")
; ----------
; Functions
; ----------
Write(txt) {
FileAppend, % txt, con
}
GetInput() {
FileReadLine, txt, con, 1
return txt
}
MoveCursor(X, Y) {
Global hOutput
VarSetCapacity(Coord, 4, 0)
NumPut(Y, Coord, 0, "Short")
NumPut(X, Coord, 2, "Short")
If (!DllCall("SetConsoleCursorPosition", UInt, hOutput, UInt, Coord))
MsgBox %ErrorLevel%`n%A_LastError%
}
GetCursor(ByRef X, ByRef Y) {
Global hOutput
VarSetCapacity(BufferInfo, 22, 0)
DllCall("GetConsoleScreenBufferInfo", UInt, hOutput, UInt, &BufferInfo)
X := NumGet(BufferInfo, 4, "Short")
Y := NumGet(BufferInfo, 6, "Short")
}
I have tried all of the following:
Code:
DllCall("SetConsoleCursorPosition", UInt, hOutput, UInt, &Coord)
DllCall("SetConsoleCursorPosition", UInt, hOutput, Int, &Coord)
DllCall("SetConsoleCursorPosition", UInt, hOutput, Int, Coord)
DllCall("SetConsoleCursorPosition", UInt, hOutput, UInt64, Coord)
DllCall("SetConsoleCursorPosition", UInt, hOutput, Int64, Coord)
DllCall("SetConsoleCursorPosition", UInt, hOutput, UInt *, Coord)
DllCall("SetConsoleCursorPosition", UInt, hOutput, Int *, Coord)
Any idea what I'm doing wrong?