The MASM Forum

General => The Campus => Topic started by: deeR44 on February 27, 2022, 05:37:37 PM

Title: What is "inkey"?
Post by: deeR44 on February 27, 2022, 05:37:37 PM
If "inkey" is a procedure or a function, what does it do and how do you work it?
Title: Re: What is "inkey"?
Post by: hutch-- on February 27, 2022, 06:12:29 PM
Its a macro that calls a procedure in the masm32 library. It stops program execution until you press a key.
Title: Re: What is "inkey"?
Post by: deeR44 on March 04, 2022, 04:24:22 PM
Hutch, is the key then available? Thank you for your reply.
Title: Re: What is "inkey"?
Post by: hutch-- on March 04, 2022, 05:16:42 PM
Just have a look at the source in the library, its really simple code.
Title: Re: What is "inkey"?
Post by: jj2007 on March 04, 2022, 08:20:22 PM
Quote from: hutch-- on March 04, 2022, 05:16:42 PM
Just have a look at the source in the library, its really simple code.

The inkey macro calls wait_key, which is at \Masm32\m32lib\wait_key.asm
Title: Re: What is "inkey"?
Post by: deeR44 on March 05, 2022, 03:52:51 PM
I see wait_key but I still haven't found "inkey". I don't know which library it's in. There're only about fifty libraries on my C: drive.
Thank you for the info.
Title: Re: What is "inkey"?
Post by: NoCforMe on March 05, 2022, 06:24:59 PM
Well, if you can't find the macro, just CALL wait_key. Does the same thing.
Title: Re: What is "inkey"?
Post by: Vortex on March 05, 2022, 07:13:32 PM
Hi deeR44,

The inkey macro is defined in the file :

\masm32\macros\macros.asm

;; ------------------------------------------------------
    ;; display user defined text, default text or none if
    ;; NULL is specified and wait for a keystroke to continue
    ;; ------------------------------------------------------
    inkey MACRO user_text:VARARG
      IFDIF <user_text>,<NULL>                  ;; if user text not "NULL"
        IFNB <user_text>                        ;; if user text not blank
          print user_text                       ;; print user defined text
        ELSE                                    ;; else
          print "Press any key to continue ..." ;; print default text
        ENDIF
      ENDIF
      call wait_key
      print chr$(13,10)
    ENDM
Title: Re: What is "inkey"?
Post by: hutch-- on March 05, 2022, 09:18:32 PM
deeR44,

"inkey" is a MACRO that calls a procedure in the MASM32 library, wait_key.asm.

The "inkey" macro is in the "\masm32\macros" directory and the file the macro is in is "macros.asm".

Why is it like this ????

The macro is easier to use and it stops a console app from exiting when its finished so you can see any results before it closes.




Title: Re: What is "inkey"?
Post by: Vortex on March 06, 2022, 07:27:42 AM
Hi Hi deeR44,

As Hutch said, the macro is easier to use. A modified version of the Microsoft example translated to Masm :

include     \masm32\include\masm32rt.inc

.code

start:

    invoke  crt_printf,\
            CTXT("Press any key to continue.",13,10)
@@:
    invoke  crt__kbhit
    test    eax,eax
    jz      @b

    invoke  crt__getch
   
    invoke  crt_printf,\
            CTXT("Key struck was %c"),eax
   
    invoke  ExitProcess,0

END start
Title: Re: What is "inkey"?
Post by: deeR44 on March 06, 2022, 09:14:38 AM
Thank all of you for the excellent help!