Forum > Windows
Keboard Input in Free Pascal under Windows 10
Weosule:
:(
Hello Everyone....
I have been using Turbo Pascal up to version 7 for DOS and Borland Delphi 7 up until the advent of Windows 7. I have recently started using Free Pascal and although I have am glad to have written some new programs in FP and recompile some programs I wrote using Turbo Pascal 7, I have been having issues recompiling and using programs that use Graphic rather than Text format. They compile but I find I have to switch to a second window to enter anything from the keyboard. It may be a noobie error or I have made a stooopid but I hope you'll not be angry with me and send a squad of trolls to my house to beat me up and skin my pet ferrit.
I have been using the following procedure to read from the keyboard and write the input to a graphic screen which worked fine up to Turbo Pascal 7. However, I did not write this code and don't know how to amend it for it to work under FP. I hope someone would be kind enough to revise it for me.
Thank you all in advance.
Weosule
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---PROCEDURE ReadlnXY(X, Y: Integer; VAR S: String); {$V-} {Relax string checking}VAR Ch: Char; { key from keyboard } Done: boolean; { our flag for quiting } CurColor: word; { color to write text in } OldX: Integer; { old x } BEGIN S := ''; CurColor := GetColor; MoveTo(X, Y); Done := False; WHILE NOT Done DO BEGIN Ch := Readkey; { get a single key } CASE Ch of #0: { extra key - two chars - let's ignore them } Ch := Readkey; #13: { return key } Done := true; { we got our string, let's go } #32..#126: { ASCII 32 (space) through 126 (tilde) } BEGIN OutText(Ch); S := Concat(S, Ch); END; #8: IF Length(S) > 0 THEN BEGIN { move back to last character } OldX := GetX - TextHeight(S[Length(S)]); MoveTo(OldX, GetY); { over write last character } SetColor(0); OutText(S[Length(S)]); SetColor(CurColor); MoveTo(OldX, GetY); { remove last character from the string } Delete(S, Length(S), 1); END; END; END; END; { ReadlnXY }
benohb:
What do you mean "Graphic" . ..
This ?? https://www.freepascal.org/docs-html-3.0.0/rtl/graph/index.html
Can you upload an image for 2 windows (screenshot)
--- Quote ---They compile but I find I have to switch to a second window to enter anything from the keyboard
--- End quote ---
Nitorami:
He is talking about the ancient graph and crt units.
The procedure does work, see the compilable code below. However, when entering the characters, you need to bring the console window into focus, not the graph window, otherwise your keyboard input goes nowhere.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses graph, crt;var col,Driver,mode: smallint; PROCEDURE ReadlnXY(X, Y: Integer; VAR S: String); {$V-} {Relax string checking} VAR Ch: Char; { key from keyboard } Done: boolean; { our flag for quiting } CurColor: word; { color to write text in } OldX: Integer; { old x } BEGIN S := ''; CurColor := GetColor; MoveTo(X, Y); Done := False; WHILE NOT Done DO BEGIN Ch := Readkey; { get a single key } CASE Ch of #0: { extra key - two chars - let's ignore them } Ch := Readkey; #13: { return key } Done := true; { we got our string, let's go } #32..#126: { ASCII 32 (space) through 126 (tilde) } BEGIN OutText(Ch); S := Concat(S, Ch); END; #8: IF Length(S) > 0 THEN BEGIN { move back to last character } OldX := GetX - TextHeight(S[Length(S)]); MoveTo(OldX, GetY); { over write last character } SetColor(0); OutText(S[Length(S)]); SetColor(CurColor); MoveTo(OldX, GetY); { remove last character from the string } Delete(S, Length(S), 1); END; END; END; END; { ReadlnXY } var s: string;begin Driver := D8bit; mode := m800x600; InitGraph (Driver,mode,''); readlnxy (100,100,s); readln;end.
Bart:
IIRC then it is not advised to use crt and graph unit together.
Bart
Weosule:
It seems strange to me that if there is an graphic output function, there is not an input function. :o
Navigation
[0] Message Index
[#] Next page