flat assembler
Message board for the users of flat assembler.

Index > Main > kbhit((())) AKA INKEY$$$

Author
Thread Post new topic Reply to topic
DOS386



Joined: 08 Dec 2006
Posts: 1900
DOS386 08 Jul 2011, 07:30
. .
. .

( if you got a bad link : TESTCMD package )

. .
. .

Just in case someone cares about ASM too ( see t=5309 "Reading keypresses with C" ) I brewed an example:

Download now 90'282 Byte's

Shots:

Image

Image

Works well with HX , ME , XP and Wi$ta Smile

Code:
; SSKBHIT

; In      : - EDI : ZERO is "LH" , non-ZERO is "EH"
; Trashes : - EAX ECX EDX
; Out     : - AL : Scancode 0 to 253, other event 254, no event 255
;           - AH : Special key and LED bits (valid for AL<254, else ZERO)

; Needs 52 Byte's on stack :
; 4 (EBX) + 4 (check) + 20 (RCI buffer) + 24 (RCI params)

; Will in any case eat away all events, so to initialize,
; just call this too and ignore the result

; We will simply do "ReadConsoleInput" as long as there is something
; available to read previously checked by "GetNumberOfConsoleInputEvents",
; because "ReadConsoleInput" hangs if no events available Sad

; Keyboard event is 1, other possible events include rat and focus.

; EventType         16 | Must be = 1 | (+ ZERO)
; BuggerAll         16 ???
; bKeyDown          32 | Only 1 bit is useful ???
; wRepeatCount      16 ???
; wVirtualKeyCode   16 ???
; wVirtualScanCode  16 | <<-- HERE | (+ 12 Byte's)
; AsciiChar         16 ???
; dwControlKeyState 32 | Only 5 or 8 or 9 bits useful | (+ 16 Byte's)
; --------------------
; Total 5 UINT32's = 20 Byte's = 160 Bits

; RIGHT_ALT_PUSHED   $0001
; LEFT_ALT_PUSHED    $0002
; RIGHT_CTRL_PUSHED  $0004
; LEFT_CTRL_PUSHED   $0008
; SHIFT_PUSHED       $0010
; NUMLOCK_ON         $0020
; SCROLLLOCK_ON      $0040
; CAPSLOCK_ON        $0080
; ENHANCED_KEY       $0100

; Scancodes :
; $2A SHIFT   left
; $36 SHIFT   right
; $1D CONTROL both !!!
; $38 ALT     both !!!

; HX :
; - RIGHT_ALT 1 also sets LEFT_CONTROL 8 giving 9 !!!
; - "Printscreen" is taken but strange
; - "Pause Break" is taken but strange
; - "Power" OK
; - Rat completely ignored

; ME :
; - "Printscreen" is taken but strange
; - Left and right rat button taken, movements too, wheel ignored

; XP :
; - "Printscreen" is ignored
; - "Power" is taken but very evil
; - Left rat button, wheel and movements ignored
; - Right rat button taken but very strange

; Wi$ta :
; - Left rat button, wheel and movements ignored
; - Right rat button taken but less strange

sskbhit:

        push   ebx
        pushd  111                  ; Check value UINT32 111
        sub    esp, 20              ; Buffer

        movntq ebx, 0
        dec    bl                   ; MOVNTQ EBX,255 | Get AL=255 and AH=ZERO

        pushd  $FFFF'FFF6           ; "-10" means "stdin"
        call   dword [GetStdHandle] ; $FFFF'FFFF is invalid (if no console ?)
        inc    eax                  ; CMPNTQ EAX, $FFFF'FFFF
        jz     short after_rd_loop  ; Console got shot by some gun geek ???
        dec    eax                  ; Is ZERO valid or not ???

event_read_loop:

        push   eax                  ; Hendaye backup (NOT for the call)
        push   eax                  ; CRAP (NOT "directly" for the call)
        push   esp                  ; Out variable address (!) (for the call)
        push   eax                  ; Hendaye for call
        call   dword [GNOCIE]       ; Uses 2 arguments
        pope   ecx                  ; Amount of events
        pope   eax                  ; Hendaye restore | Now stack fine (-2Cool
        cmpntq ecx, 0
        je     short after_rd_loop  ; No more events, exit the loop

        mov    ecx, esp                 ; Backup address before PUSH'ing !!!
        push   eax                      ; Hendaye backup (NOT for the call)
        push   eax                      ; CRAP (NOT "directly" for the call)
        push   esp                      ; Out var address (!) (for the call)
        pushd  1                        ; Amount of records (!) to read
        push   ecx                      ; Buffer (20 Byte's hopefully)
        push   eax                      ; Hendaye for call
        call   dword [ReadConsoleInput] ; Uses 4 arguments
    


Yeah Smile

Another one: http://board.flatassembler.net/topic.php?t=1953


Last edited by DOS386 on 10 Apr 2013, 13:34; edited 5 times in total
Post 08 Jul 2011, 07:30
View user's profile Send private message Reply with quote
idle



Joined: 06 Jan 2011
Posts: 440
Location: Ukraine
idle 08 Jul 2011, 08:09
zipped tar - why?
did uoy expect a one to ask Smile
Post 08 Jul 2011, 08:09
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1900
DOS386 02 Aug 2011, 12:50
idle wrote:
zipped tar - why? did uoy expect a one to ask


YES Shocked

UPDATED

- Fixed critical bugs
- Nicer code
- Better comments
- Added EH vs LH mode
- Added/confirmed Vista support
- Increased BLOAT by factor 11 (challenge: | task1: guess who to blame for this | task2: blame him Wink )

Please download it again (previously had 12 downloads, among them 0 ... 12 by myself).
Post 02 Aug 2011, 12:50
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 02 Aug 2011, 13:25
Doesn't work for PrintScreen or Pause Razz

Quote:
define pope pop

This never gets old Very Happy
Post 02 Aug 2011, 13:25
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1900
DOS386 02 Aug 2011, 13:26
vid wrote:
Doesn't work for PrintScreen or Pause Razz


RTFS (or tell me what OS you tested).
Post 02 Aug 2011, 13:26
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 02 Aug 2011, 13:31
WinXP 32-bit
Post 02 Aug 2011, 13:31
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.