✅ Is it possible to ask check for a keypress without pausing the whole console?
Kinda new to c# so i dont rlly know alot, but i started a project and i literally have no clue how to ask for a keypress w out pausing and waiting for one, ive seen examples on stack like
Task.Factory.StartNew(() => Console.ReadKey(true)).Wait(TimeSpan.FromSeconds(0.2)); but i cant assign that to var key to use as controls etc, if anyone wants to check through my code more i can send screenshtos or try open a git
Task.Factory.StartNew(() => Console.ReadKey(true)).Wait(TimeSpan.FromSeconds(0.2)); but i cant assign that to var key to use as controls etc, if anyone wants to check through my code more i can send screenshtos or try open a git
50 Replies
Check
Console.KeyAvailable
before calling Console.ReadKey
uhh lemme try that
kinda worked
the code runs smoothly but i dont think it takes input
ima go check it out some more
It gets input
Console.KeyAvailable
returns true if there's data in stdin, and Console.ReadKey will read a key from stdinlike this?
Yeah
um
Also
it doesnt change the colour
yeah?
You don't need
if (Console.KeyAvailable == true)
you can just do
if (Console.KeyAvailable)
fair point
hold on im gonna go use breakpoints and see if that is ever true
brb
its always false
im trying to make mspaint in console atm bc im bored at school and had no idea what to do
Show your full code please 😅
oh sure
If it's too long
$paste
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
BlazeBin - btmppmzbjait
A tool for sharing your source code with the world!
i took some stuff from stack overflow, like to know where cursor is etc but i hard coded parts so you might need to change the numbers for ur screen
its prolly insanely inefficient but this is js a first draft for school atm
also thank you sm kouhai
ALSO I LITERALYL STARTED MAKING IT TODAY SO NOT MUCH HAS BEEN MADE
i think my code killed them
The problem is most likely with
ColourList
oh i see
can you explain why?
Well
yeah
um
i have it so you can go back and forth tho
No, what you have is literally what I copy pasted
OH
WAIT
I SE
I REPEATED MYSELF IN THE CODE
THANK YOU SM
WAIT NO
im dumb
this is for a seperate thing
uhh hold on
Yes, the problem is with it
it prints out this
You're setting ForegroundColor to
i
to display the colors, but ForegroundColor is not being reset to the previous colorcolourlist does that
Yes, and that's the problem
oh
Oh
i se
Let's say before exeuting the method that ForegroundColor is
DarkRed
We enter the functionits set to white after running
ForegroundColor is getting set to
i
and its not set back to dark red
Yup
so when console prints other things
hold on
ah
okay
ill go figure how to get it to stay
thank you so so much kouhai
im a bit dum at times
It's all good
ill be back after running some tests ig
Also, your program will crash here
Console.SetCursorPosition(defPnt.X * Console.WindowWidth / 1919, defPnt.Y * Console.WindowHeight / 1079);
Because sometimes the cursor will be outside the console screenyeah
it only crashes if i hover over x
like the red close tab
otherwise it runs fine
so it doesnt rlly matter for rn
Because it's outside the console screen 😜
yeah lol
but if ur goin on X your shutting the program down anyways
Well...a program shouldn't crash because the user is hovering over
X
ill fix it after i get everything else working
thats like
my lowest priority problem rn 😭
OKAY
IT WORKS
drew a frog w it
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
If you have no further questions, please use /close to mark the forum thread as answered