{{fbdoc item="title" value="SCREEN (Console)"}}---- Gets the character or color attribute at a given location {{fbdoc item="syntax"}}## [[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Screen** ( [[KeyPgByval|byval]] row [[KeyPgAs|as]] [[KeyPgLong|long]], [[KeyPgByval|byval]] column [[KeyPgAs|as]] [[KeyPgLong|long]], [[KeyPgByval|byval]] colorflag [[KeyPgAs|as]] [[KeyPgLong|long]] = 0 ) [[KeyPgAs|as]] [[KeyPgUlong|ulong]] ## {{fbdoc item="usage"}}## //result// = **Screen**( //row//, //column// [, //colorflag// ] ) ## {{fbdoc item="param"}} ##//row//## 1-based offset from the top left corner of the console. ##//column//## 1-based offset from the top left corner of the console. ##//colorflag//## If equal to 0, the [[CptAscii|ASCII]] code is returned, otherwise the color attribute is returned. If omitted, it defaults to 0. {{fbdoc item="ret"}} The [[CptAscii|ASCII]] or color attribute of the character. {{fbdoc item="desc"}} ##**Screen**## returns the character or the color attribute found at a given position of a console output. It works in console mode and in graphics mode. The format of the color attribute depends on the current color depth: If the color type is a palette type with up to 4 bits per pixel (such as the Win32 console), then the color attribute is an 8-bit value, where the higher four bits hold the cell background color and the lower four bits hold the foreground (character) color. If the color type is an 8-bit palette, then the color attribute is a 16-bit value, where the high byte holds the background color and the low byte holds the foreground color. If the color type is full color, then the color attribute is a 32-bit integer, holding a single color value. If ##//colorflag//## is equal to 1, then the foreground color is returned; if ##//colorflag//## is equal to 2, then the background color is returned. The color values for the standard 16 color palette are: {{table columns="4" cellpadding="2" cells="Value;Color;Value;Color;0;Black;8;Gray;1;Blue;9;Bright Blue;2;Green;10;Bright Green;3;Cyan;11;Bright Cyan;4;Red;12;Bright Red;5;Magenta;13;Pink;6;Brown;14;Yellow;7;White;15;Bright White"}} {{fbdoc item="ex"}} {{fbdoc item="filename" value="examples/manual/console/screen-func.bas"}}%%(freebasic) dim character_ascii_value as ulong dim attribute as ulong dim background as ulong dim cell_color as ulong dim row as long, col as long character_ascii_value = Screen( row, col ) attribute = Screen( row, col, 1 ) background = attribute shr 4 cell_color = attribute and &hf %% {{fbdoc item="filename" value="examples/manual/gfx/screen-func1.bas"}}%%(freebasic) '' open a graphics screen with 4 bits per pixel '' (alternatively, omit this line to use the console) screenres 320, 200, 4 '' print a character color 7, 1 print "A" dim as ulong char, col, fg, bg '' get the ASCII value of the character we've just printed char = screen(1, 1, 0) ''get the color attributes col = screen(1, 1, 1) fg = col and &HF bg = (col shr 4) and &HF print using "ASCII value: ### (""!"")"; char; chr(char) print using "Foreground color: ##"; fg print using "Background color: ##"; bg sleep %% {{fbdoc item="filename" value="examples/manual/gfx/screen-func2.bas"}}%%(freebasic) '' open a graphics screen with 8 bits per pixel screenres 320, 200, 8 '' print a character color 30, 16 print "Z" dim as ulong char, col, fg, bg '' get the ASCII value of the character we've just printed char = screen(1, 1, 0) ''get the color attributes col = screen(1, 1, 1) fg = col and &HFF bg = (col shr 8) and &HFF print using "ASCII value: ### (""!"")"; char; chr(char) print using "Foreground color: ###"; fg print using "Background color: ###"; bg sleep %% {{fbdoc item="filename" value="examples/manual/gfx/screen-func3.bas"}}%%(freebasic) '' open a full-color graphics screen screenres 320, 200, 32 '' print a character color rgb(255, 255, 0), rgb(0, 0, 255) 'yellow on blue print "M" dim as ulong char, fg, bg '' get the ASCII value of the character we've just printed char = screen(1, 1, 0) ''get the color attributes fg = screen(1, 1, 1) bg = screen(1, 1, 2) print using "ASCII value: ### (""!"")"; char; chr(char) print using "Foreground color: &"; hex(fg, 8) print using "Background color: &"; hex(bg, 8) sleep %% {{fbdoc item="target"}} - On the Linux version, the value returned can differ from the character shown on the console. For example, unprintable control codes - such as the ##LF## character (##10##) that implicitly occurs after the end of ##[[KeyPgPrint|Print]]##ed text - may be picked up instead of the untouched character in its place. {{fbdoc item="diff"}} - In QB ##**Screen**## triggered an error if the coordinates were out of screen. {{fbdoc item="see"}} - ##[[KeyPgScreengraphics|Screen (Graphics)]]## - ##[[KeyPgColor|Color]]## {{fbdoc item="back" value="CatPgConsole|Console Functions"}}