Terminal control/Positional read: Difference between revisions

Content added Content deleted
(added qbasic; edited rexx to match the task spec)
(→‎{{header|AutoHotkey}}: Submit AutoHotkey example)
Line 3: Line 3:
Determine the character displayed on the screen at column 3, row 6 and store that character in a variable.
Determine the character displayed on the screen at column 3, row 6 and store that character in a variable.
[[Terminal Control::task| ]]
[[Terminal Control::task| ]]
=={{header|AutoHotkey}}==
{{works with|AutoHotkey_L}}
<p>AutoHotkey is not built for the command line, so we call the WinAPI directly.</p><p>For fun, this writes random characters to the command window so that it has something to retrieve. </p>
<lang AHK>DllCall( "AllocConsole" ) ; create a console if not launched from one
hConsole := DllCall( "GetStdHandle", int, STDOUT := -11 )
Loop 15
WriteConsole(hConsole, RandChars(7) "`n")

MsgBox % ReadConsoleOutputCharacter(hConsole, 1, 3, 6)
; === The below simply wraps part of the WinAPI ===

WriteConsole(hConsole, text){
VarSetCapacity(out, 16)
If DllCall( "WriteConsole", UPtr, hConsole, Str, text, UInt, StrLen(text)
, UPtrP, out, uint, 0 )
return out
return 0
}
ReadConsoleOutputCharacter(hConsole, length, x, y){
VarSetCapacity(out, length * (1 << !!A_IsUnicode))
VarSetCapacity(n, 16)
if DllCall( "ReadConsoleOutputCharacter"
, UPtr, hConsole
, Str, out
, UInt, length
, UInt, x | (y << 16)
, UPtrP, n )
&& VarSetCapacity(out, -1)
return out
return 0
}
RandChars(n){
Loop % n
{
Random, asc, % asc("A"), % Asc("Z")
out .= Chr(asc)
}
return out
}</lang>

=={{header|BASIC}}==
=={{header|BASIC}}==