flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > Getting key presses in windows & x64 debugging options

Author
Thread Post new topic Reply to topic
nullbyte



Joined: 10 Jul 2018
Posts: 2
Hello,

Sorry for what is probably a moronic n00b question, but I'm having trouble with windows character input. I'd like to register key presses, but the following doesnt work. Do I need to use the Microsoft API instead (as w/ WriteConsole?)

The long term goal would be to do this in an OpenGL window, but I figured a console is a start.

Second, what debuggers do you use in 64 bit Windows land? My favorites (OllyDbg/Immunity) seem to only support 32 bit PEs.


Code:
include 'win64ax.inc' .code start: invoke AllocConsole invoke GetStdHandle, STD_OUTPUT_HANDLE mov [outhandle], eax invoke WriteConsole, [outhandle], "Hit a key", 10, numwrite, 0 mov ah, 01h ; char read int 21h ; interrupt mov [char], al ; store our char invoke WriteConsole, [outhandle], "After int21", 12, numwrite, 0 invoke WriteConsole, [outhandle], char, 1, numwrite, 0 invoke Sleep, 2000 invoke ExitProcess,0 .end start .data outhandle dd ? numwrite dd ? char db ?
Post 11 Jul 2018, 15:27
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6872
Location: Kraków, Poland
nullbyte wrote:
Sorry for what is probably a moronic n00b question, but I'm having trouble with windows character input. I'd like to register key presses, but the following doesnt work. Do I need to use the Microsoft API instead (as w/ WriteConsole?)
Yes, you have to use the Windows API. DOS interrupt functions do not exist in Windows subsystem (and modern Windows systems do not even have a DOS subsystem anymore).

nullbyte wrote:
Second, what debuggers do you use in 64 bit Windows land? My favorites (OllyDbg/Immunity) seem to only support 32 bit PEs.
FDBG is one developed by a member of this forum (Feryno).
Post 11 Jul 2018, 15:36
View user's profile Send private message Visit poster's website Reply with quote
nullbyte



Joined: 10 Jul 2018
Posts: 2
Thank you Tomasz! I'll check out FDBG.

In case anyone is wondering the same thing:
Seems like for console this works:

ReadConsoleInput(): https://docs.microsoft.com/en-us/windows/console/readconsoleinput
This Stackoverflow provides an example https://stackoverflow.com/questions/15993882/detecting-key-events

and w/ a bit of modification
Code:
.while invoke ReadConsoleInput, [inhandle], input, 1, count ; read input cmp [input.event.VirtScanCode], 51h ; check if our scan code is Q je .exit ; if it is jump invoke WriteConsole,[outhandle],input.event.char,1,numwritten,0 ; print character .endw .exit: invoke WriteConsole,[outhandle],"You pressed Q",14,numwritten,0 invoke Sleep, 1000 invoke ExitProcess, 0


For a window, this seems like the way to go:
https://docs.microsoft.com/en-us/windows/desktop/inputdev/wm-keydown
Post 12 Jul 2018, 10:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15870
Location: 162173 Ryugu
You can also encode the characters directly:
Code:
cmp [input.event.VirtScanCode], 'Q' ;<--- use the Q character in the code for better readability.
Post 12 Jul 2018, 10:34
View user's profile Send private message Visit poster's website 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 © 2004-2018, Tomasz Grysztar.

Powered by rwasa.