 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Slanter
Joined: 28 May 2008 Posts: 739 Location: Minnesota, USA
|
Posted: Fri Jan 02, 2009 1:50 am Post subject: DllCall "SetConsoleCursorPosition" - Going to 0,0 |
|
|
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? _________________ Unless otherwise stated, all code is untested
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4367 Location: Qld, Australia
|
Posted: Fri Jan 02, 2009 2:31 am Post subject: |
|
|
There are two problems.
- Edit: The following was caused by SciTE redirecting StdOut:
GetStdHandle(-11) does not return a handle to a console output buffer. This is why SetConsoleCursorPosition sets A_LastError to ERROR_INVALID_HANDLE=6. Use the following instead:
| Code: | hOutput := DllCall("CreateFile" ,"str","CONOUT$" ,"uint",0xC0000000 ,"uint",2 ,"uint",0 ,"uint",3 ,"uint",0 ,"uint",0)
|
SetConsoleCursorPosition expects a COORD structure. What you have is almost correct, but for the "UInt" type DllCall expects a string of numeric characters representing an unsigned integer, not a binary number. Also, X and Y are around the wrong way. Use one of the following instead:
| Code: | VarSetCapacity(Coord, 4, 0)
NumPut(X, Coord, 0, "Short")
NumPut(Y, Coord, 2, "Short")
If (!DllCall("SetConsoleCursorPosition", UInt, hOutput, UInt, NumGet(Coord)))
; OR
If (!DllCall("SetConsoleCursorPosition", UInt, hOutput, UInt, X | Y<<16))
|
|
|
| Back to top |
|
 |
Slanter
Joined: 28 May 2008 Posts: 739 Location: Minnesota, USA
|
Posted: Fri Jan 02, 2009 6:09 am Post subject: |
|
|
Great! Thanks! About the X and Y being switched, I think I did that to check if anything would happen (not really sure why I did that anymore tbh), then forgot to switch it back . _________________ Unless otherwise stated, all code is untested
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|