Author Topic: inkey hangs  (Read 570 times)

markallyn

  • Member
  • **
  • Posts: 122
inkey hangs
« on: September 17, 2017, 03:16:20 AM »
Hello everyone,

Can anybody suggest how to stop the inkey command from hanging.  It prints out the message, but then hangs.  To get out I have to do CTRL C.

Thanks,
Mark Allyn

aw27

  • Member
  • ****
  • Posts: 855
  • Let's Make ASM Great Again!
Re: inkey hangs
« Reply #1 on: September 17, 2017, 03:47:12 AM »
Can anybody suggest how to stop the inkey command from hanging.  It prints out the message, but then hangs.  To get out I have to do CTRL C.
inkey is a macro that calls a masm32 library function which in turn calls MSVCRT functions.
Probably, you should post a proof that it hangs.

markallyn

  • Member
  • **
  • Posts: 122
Re: inkey hangs
« Reply #2 on: September 17, 2017, 04:33:41 AM »
Hi aw27,

Here's the program.  It is just a test run of the masm32 macros to do an dwtoa function.  Try it out, if you don't mind.  I just did and as I say, it hangs.

Quote
include \masm32\include\masm32rt.inc
option casemap:NONE


.DATA
num1   DWORD   123456
frmt1   BYTE   "The ascii version of num is : %s",13,10,0

.DATA?
buff   DWORD 20 DUP (?)

.CODE
start:
   inkey
   mov   eax, num1
   INVOKE   dwtoa, eax, ADDR buff
   INVOKE   crt_printf, ADDR frmt1, ADDR buff
   INVOKE   ExitProcess, 0
end start

Thanks,
Mark

dedndave

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: inkey hangs
« Reply #3 on: September 17, 2017, 04:37:45 AM »
it's waiting for a keypress :)

dedndave

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: inkey hangs
« Reply #4 on: September 17, 2017, 04:41:09 AM »
... if what you are after is a non-blocking "inkey" (similar to the old basic "inkey"), let me know

dedndave

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: inkey hangs
« Reply #5 on: September 17, 2017, 04:44:08 AM »
this may not be my latest one - lol
MSVCRT.INC + LIB req'd

Code: [Select]
InKyb   PROC

;Polled Keyboard Input - DednDave 8, 2010
;
;This function returns a keystroke in EAX if there is one in the buffer.
;If the buffer is empty, the function returns immediately.
;
;If the keyboard buffer is empty, AH = 0, AL = 0, ZF = 1.
;If the stroke is a regular key, AH = 0, AL = key char, ZF = 0.
;If the stroke is an extended key, AH = extended key, AL = E0h, ZF = 0.
;If the stroke is a function key, AH = function key, AL = 0, ZF = 0.
;
;ECX, EDX are not preserved.

        call    crt__kbhit
        or      eax,eax
        jz      InKyb1

        call    crt__getch
        and     eax,0FFh
        jz      InKyb0

        cmp     al,0E0h
        jnz     InKyb1

InKyb0: push    eax
        call    crt__getch
        pop     edx
        shl     eax,8
        or      eax,edx

InKyb1: retn

InKyb   ENDP

markallyn

  • Member
  • **
  • Posts: 122
Re: inkey hangs
« Reply #6 on: September 17, 2017, 04:46:27 AM »
Hi Dave,

I have been pressing "enter" and nothing happens.  Are you saying that it should be some other key?

BTW, I linked this with the /SUBSYTEM:console switch.

The printf() macro works fine.

I think I am indeed looking for what you  refer to as a "non-blocking 'inkey'.  What's the difference?

Thanks for responding.  Much appreciated.

Regards,
Mark Allyn

dedndave

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: inkey hangs
« Reply #7 on: September 17, 2017, 04:53:35 AM »
the enter key should work
but, yah - i figured you wanted a polled or non-blocking routine (posted above)

dedndave

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: inkey hangs
« Reply #8 on: September 17, 2017, 04:57:17 AM »
i added another inkey before exit so you can see the result before the console window closes
the enter key works fine, here

jj2007

  • Member
  • *****
  • Posts: 7756
  • Assembler is fun ;-)
    • MasmBasic
Re: inkey hangs
« Reply #9 on: September 17, 2017, 05:45:22 AM »
Mark, how does this one behave on your machine?
Code: [Select]
include \masm32\include\masm32rt.inc

.code
start:
  inkey "hit a key"
  print "bye"
  invoke Sleep, 2000
  exit

end start

markallyn

  • Member
  • **
  • Posts: 122
Re: inkey hangs
« Reply #10 on: September 17, 2017, 05:57:14 AM »
Hi Dave and jj2007,

Dave:  Did you send me the write file in test.zip?  The asm code looks just like the one I sent you.

jj:  I ran your code and it behaves just like mine.  It prints out "hit a key", then hangs.  I have to hit CTRL C to get out (the process is still running), and when I do I clobber the shell so that it doesn't respond to the keyboard and have grab a new one.

Thanks for helping.

Mark

dedndave

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: inkey hangs
« Reply #11 on: September 17, 2017, 06:29:24 AM »
it is the same as yours except i added another "inkey" line

the command lines to build it should look something like this:

Code: [Select]
ml /c /coff test.asm
Link /SUBSYSTEM:CONSOLE /OPT:NOREF test.obj

the 32-bit linker should be used

aw27

  • Member
  • ****
  • Posts: 855
  • Let's Make ASM Great Again!
Re: inkey hangs
« Reply #12 on: September 17, 2017, 07:41:40 AM »
Mark,
You must test it in the command prompt, not a shell.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4934
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: inkey hangs
« Reply #13 on: September 17, 2017, 03:44:58 PM »
Mark,

This is the type of code that "inkey" is used in.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                     Build this console app with
                  "MAKEIT.BAT" on the PROJECT menu.
        ----------------------------------------------------- *

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey "Press any key to exit 'inkey' :]"
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    print "Do what you want to do here.",13,10,13,10

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

markallyn

  • Member
  • **
  • Posts: 122
Re: inkey hangs
« Reply #14 on: September 17, 2017, 10:52:40 PM »
Hutch,

Thanks.  I'll give it a try!  I'll let you know what happened.

Mark