flat assembler
Message board for the users of flat assembler.

Index > Main > Simulate key press from keyboard

Author
Thread Post new topic Reply to topic
flyff



Joined: 17 Mar 2006
Posts: 3
flyff 17 Mar 2006, 07:18
Hello all,

I am trying to create a small program for a game that I am playing. The purpose of this program is to run in the background which simulates keys being pressed from the keyboard. So far I am able to insert keys to the keyboard buffer using the INT 16H; function 05H. However, the keys in the buffer are not being detected in the game.

I have pasted my code below so you people can have a better understanding what I am doing.

Thanks in advance,

PS: I am using TASM to compile my program.

Code:
; Game buff bot
; Last updated : 03/16/2006 07:00 pm

;--------------------------------------

TITLE   GAME BUFF BOT
        .MODEL  SMALL
        .STACK  100H
        .DATA

MENU1   DB 'Game buff bot menu.',0AH,0DH,'$'
MENU2   DB '~~~~~~~~~~~~~~~~~~~',0AH,0DH,'$'
MENU3   DB '| F11: Run bot    |',0AH,0DH,'$'
MENU4   DB '| F12: Exit       |',0AH,0DH,'$'

        .CODE
        .386

;--------------------------------------

; Macro function to output text
OUTPUT  MACRO   TEXT,LENGTH,POSITION
        MOV     AH,13H                  ; Request display string
        MOV     AL,00H                  ; Display string and attribute
        MOV     BH,00H                  ; Page number
        MOV     BL,07H                  ; Change colour of text
        LEA     BP,TEXT                 ; Output text
        MOV     CX,LENGTH               ; Length of text
        MOV     DX,POSITION             ; Set row, col
        INT     10H
        ENDM

; Function to display menu
MENU    PROC    NEAR
        PUSHA
        OUTPUT  MENU1,13H,0201H         ; Row = 02, Col = 01
        OUTPUT  MENU2,13H,0301H         ; Row = 03, Col = 01
        OUTPUT  MENU3,13H,0401H         ; Row = 04, Col = 01
        OUTPUT  MENU4,13H,0501H         ; Row = 05, Col = 01
        OUTPUT  MENU2,13H,0601H         ; Row = 06, Col = 01
        POPA
        RET
MENU    ENDP

; Function to clear the screen
CLRSCR  PROC    NEAR
        PUSHA
        MOV     AX,0600H
        MOV     BH,07H
        MOV     CX,0000H
        MOV     DX,184FH
        INT     10H
        POPA
        RET
CLRSCR  ENDP

;--------------------------------------

; Main program
MAIN    PROC
        MOV     AX,@DATA
        MOV     DS,AX
        MOV     ES,AX
        CALL    CLRSCR
        CALL    MENU

QUERY:  MOV     AH,10H
        INT     16H
        CMP     AX,8500H        ; F11 - start bot
        JE      BOT
        CMP     AX,8600H        ; F12 - quit
        JE      QUIT
        JMP     QUERY

BOT:    MOV     AH,05H
        MOV     CH,1EH          ; ascii
        MOV     CL,61H          ; scan code
        INT     16H
        MOV     AH,01H
        INT     21H
        CMP     AX,8500H        ; F11
        JE      QUIT
        JMP     BOT

QUIT:   MOV     AX,4C00H
        INT     21H
MAIN    ENDP
        END     MAIN            ; End of program
    
Post 17 Mar 2006, 07:18
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 17 Mar 2006, 07:26
If it is a Windows game then you are better off cheating with SendKeys API Very Happy
Post 17 Mar 2006, 07:26
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Mar 2006, 09:05
most DOS games weren't using int 16h to detect keys, they used own handlers, which were so accessing directly to kbd port. So it won't be that easy...
Post 17 Mar 2006, 09:05
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
flyff



Joined: 17 Mar 2006
Posts: 3
flyff 17 Mar 2006, 16:20
Madis731 wrote:
If it is a Windows game then you are better off cheating with SendKeys API Very Happy


Thanks for your quick response and yes this game is a windows base game. I searched on the forum to find out more about SendKeys, yet there wasn't much information about it.

I did a google search on SendKeys but it kept on refering me to something related to visual basic. Is SendKeys a visual basic command or an assembly command?

Can someone tell me what's the best solution to my problem. I am quite lost now and any help, links and examples would be much appreciate.

Thanks in advance,

PS: I'm not cheating, i'm finding a way to better manage my time =P
Post 17 Mar 2006, 16:20
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 17 Mar 2006, 18:00
Your program is a DOS-executable so you have to learn some new things. Making PE executables is explained here on the forums and they come with Windows package of the FASM. You can have a look of the syntax on the MSDN, but can't help you any further because learning Windows API takes time and just giving you some code won't solve the problem Wink

Good luck!

EDIT:
SendKeys is NOT in the Windows API but its somekind of a wrapper in languages like Visual Basic etc.


Last edited by Madis731 on 20 Mar 2006, 08:37; edited 1 time in total
Post 17 Mar 2006, 18:00
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 18 Mar 2006, 02:10
flyff wrote:
Madis731 wrote:
If it is a Windows game then you are better off cheating with SendKeys API Very Happy


Thanks for your quick response and yes this game is a windows base game. I searched on the forum to find out more about SendKeys, yet there wasn't much information about it.

I did a google search on SendKeys but it kept on refering me to something related to visual basic. Is SendKeys a visual basic command or an assembly command?

Can someone tell me what's the best solution to my problem. I am quite lost now and any help, links and examples would be much appreciate.

Thanks in advance,

PS: I'm not cheating, i'm finding a way to better manage my time =P


windows API can be called from pretty much any language that can build PE applications (vb, asm, etc)

but ive never heard of SendKeys :S, and all results on the MSDN returned VB related stuff, so maybe it is a vb specific function from the vb .dll's

i use keybd_event for simulating key presses

http://tinyurl.com/5s42w

Code:
KEYEVENTF_KEYDOWN = $00

push 0
push KEYEVENTF_KEYDOWN
push 0
push VIRTUAL_KEY_CODE ;e.g. VK_RETURN
call [keybd_event]
    


it may keep the key 'pressed' untill you call it again with KEYEVENTF_KEYUP

_________________
redghost.ca
Post 18 Mar 2006, 02:10
View user's profile Send private message AIM Address MSN Messenger Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 18 Mar 2006, 03:08
This old thread may also help.
It has a code snippet that gives an example of using keybd_event to send a string of text to a window.

It clones the SendKeys function in VB.
http://board.flatassembler.net/topic.php?t=3222
Post 18 Mar 2006, 03:08
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
flyff



Joined: 17 Mar 2006
Posts: 3
flyff 18 Mar 2006, 21:58
Thanks everybody for your replies. I found a small program whiched used the keybd_event function and tried using it on the game...still no luck. I do know that this program is working since I was able to send the simulate key press to notepad. I guess this game has some kind of protection against this kind of use. It looks like i'm forced to abondon this project >_< Here's the link which I found this program if anyone is interested.

http://web3.codeproject.com/cpp/sendkeys_cpp_Article.asp

Again, thank you everyone for your help.
Post 18 Mar 2006, 21:58
View user's profile Send private message Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier 19 Mar 2006, 03:52
flyff,

I'm not sure if this will help in your instance, but look at:

AttachThreadInput

hth,

farrier

_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 19 Mar 2006, 03:52
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 20 Mar 2006, 08:35
I'm glad you got it almost working and sorry for misleading you - I thought that the Windows's API also holds SendKeys somewhere Sad
Post 20 Mar 2006, 08:35
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger 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.