News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Detect or Get Keypress

Started by raleep, March 12, 2015, 01:14:58 PM

Previous topic - Next topic

rrr314159

I know this is a dumb question, but I don't know why it is ... why don't u use the extremely straightforward example I posted?
I am NaN ;)

jj2007

Quote from: rrr314159 on March 15, 2015, 02:31:42 PM
why don't u use the extremely straightforward example I posted?

OP wants any key, including Shift etc; which, btw, works with the example that I posted
(just to keep up the competitive spirit here  :badgrin: )

rrr314159

Competition is a fine thing, keeps everyone on their toes, establishes camaraderie and a mutual sense of shared progress. It's great except that, sometimes, when carried too far, it can lead to a very undesirable consequence, which ruins the friendly spirit hutch works so assiduously to cultivate here - and that's no good. That undesirable consequence is: sometimes I lose!

In this case, you're right, OP asked for *all* keys; your routine does that. However - OP is working with dedndave to get a routine working with _getch, even as we speak. Deduction, *all* keys isn't so critical. My example (which I slaved over for, at the very least, a minute or two) also uses _getch; works; is as simple as dirt; so why not start there, and move up to GetKeyboardState after, if really desired?

Moving along, the way you do GetKeyboardState is vey clean compared to hack jobs I've seen. I guess the call to GetKeyState is necessary, or you wouldn't do it, but I don't really know why. OP mentioned GetAsyncKeyState; if that's really wanted your routine (I think) is easily modified to use that instead ... ?

So I reckon you win, still there's a decent chance that *all* keys really isn't necessary.



I am NaN ;)

jj2007

Quote from: rrr314159 on March 15, 2015, 05:13:16 PMMoving along, the way you do GetKeyboardState is vey clean compared to hack jobs I've seen. I guess the call to GetKeyState is necessary

It seems so. Without it, no success. Apparently GetKeyboardState needs some gentle reminder that it has been asked to do something. My best guess is that the console has a message loop, and therefore needs a message of some kind to be activated.

Now let's wait for Dave's best guess 8)

raleep

Quote from: dedndave on March 15, 2015, 06:10:05 AM
sbrtst_test:
call beep0
pushad
call wosw
invoke crt__getch
popad
   jmp sbrtst_test


that code will continually loop and beep whenever a key is pressed

first of all, the PUSHAD/POPAD preserves and restores all the registers, including EAX
crt__getch returns a value in EAX that should be tested for key-presses (destroyed by POPAD)
and - you don't display that value

also, the loop ends with an unconditional branch back to the top
you may way to use a conditional branch, instead

I expected crt__getch not to return until a key was pressed. :redface:
I'll need to work on this some more.
Thank you.

dedndave

we don't see the code for beep0 or wosw