Welcome, Guest. Please login or register.

Author Topic: Simulate key press, help need.  (Read 7375 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« on: May 29, 2006, 01:26:36 AM »
Code: [Select]

;
; send input event with input.device v1.0.0
;
; Written by Harry Sintonen. Public Domain.
;

        include "exec/types.i"
        include "exec/nodes.i"
        include "exec/ports.i"
        include "exec/lists.i"
        include "devices/input.i"
        include "devices/inputevent.i"

_LVOFindTask            EQU     -294
_LVOAllocSignal         EQU     -330
_LVOFreeSignal          EQU     -336
_LVOOpenDevice          EQU     -444
_LVOCloseDevice         EQU     -450
_LVODoIO                EQU     -456

        STRUCTURE iedata,ie_SIZEOF
        ALIGNLONG
        LABEL iedata_SIZE

main:
        lea     -iedata_SIZE(sp),sp

        ; send key a press with left shift
        move.b  #IECLASS_RAWKEY,ie_Class(sp)
        clr.b   ie_SubClass(sp)
        move.w  #$20,ie_Code(sp)
        move.w  #IEQUALIFIER_LSHIFT,ie_Qualifier(sp)
        clr.l   ie_EventAddress(sp)
        move.l  sp,a0
        bsr     sendevent

        ; send key a release with left shift
        move.b  #IECLASS_RAWKEY,ie_Class(sp)
        clr.b   ie_SubClass(sp)
        move.w  #$20|IECODE_UP_PREFIX,ie_Code(sp)
        move.w  #IEQUALIFIER_LSHIFT,ie_Qualifier(sp)
        clr.l   ie_EventAddress(sp)
        move.l  sp,a0
        bsr     sendevent

        lea     iedata_SIZE(sp),sp
        moveq   #0,d0
        rts


        STRUCTURE data,0
        STRUCT   data_mp,MP_SIZE
        STRUCT   data_ioreq,IOSTD_SIZE
        ALIGNLONG
        LABEL    data_SIZE

; send inputevent
; IN:  a0 = inputevent to send
; OUT: d0 = zero for error, nonzero for success
sendevent:
        movem.l d2/a2/a6,-(sp)
        move.l  (4).w,a6
        move.l  a0,a2
        moveq   #0,d2
        lea     -data_SIZE(sp),sp

        ; init msgport
        moveq   #-1,d0
        jsr     _LVOAllocSignal(a6)
        move.b  d0,data_mp+MP_SIGBIT(sp)
        bmi     .nosignal
        move.b  #NT_MSGPORT,data_mp+LN_TYPE(sp)
        move.b  #PA_SIGNAL,data_mp+MP_FLAGS(sp)
        sub.l   a1,a1
        jsr     _LVOFindTask(a6)
        move.l  d0,data_mp+MP_SIGTASK(sp)
        lea     data_mp+MP_MSGLIST(sp),a0
        NEWLIST a0

        ; init ioreq
        move.b  #NT_REPLYMSG,data_ioreq+LN_TYPE(sp)
        lea     data_mp(sp),a0
        move.l  a0,data_ioreq+MN_REPLYPORT(sp)
        move.w  #IOSTD_SIZE,data_ioreq+MN_LENGTH(sp)

        ; open input.device
        lea     .inputname(pc),a0
        moveq   #0,d0
        moveq   #0,d1
        lea     data_ioreq(sp),a1
        jsr     _LVOOpenDevice(a6)
        tst.b   d0
        bne     .noinput

        ; send input event
        lea     data_ioreq(sp),a1
        move.w  #IND_WRITEEVENT,IO_COMMAND(a1)
        move.l  a2,IO_DATA(a1)
        jsr     _LVODoIO(a6)
        tst.b   d0
        seq     d2

        ; close input.device
        lea     data_ioreq(sp),a1
        jsr     _LVOCloseDevice(a6)
.noinput:
        ; free the signal
        moveq   #0,d0
        move.b  data_mp+MP_SIGBIT(sp),d0
        jsr     _LVOFreeSignal(a6)

.nosignal:
        lea     data_SIZE(sp),sp
        move.l  d2,d0
        movem.l (sp)+,d2/a2/a6
        rts

.inputname:
        dc.b    'input.device',0
        CNOP    0,2

Read input.device/IND_WRITEEVENT autodoc for more details.

Quote
and for no-multitask games also?

I'm afraid there is no way to do that. Only OS friendly apps will get the input events...
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« Reply #1 on: May 29, 2006, 11:47:40 AM »
Quote
There is a site where i can download Amiga include files for assembler?

NDK3.9.lzx

The assembler includes are in NDK_3.9/Include/include_i/

To comple the source code with phxass, unarchive the NDK3.9.lzx and then: phxass I=whatever:is/the/path/NDK_3.9/Include/include_i sendevent.asm
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« Reply #2 on: May 29, 2006, 11:51:27 AM »
Quote
I think you should contact those guys that make whdload game loaders. Ask them how they made for eg. F10 exit the game.

That is completely different thing, it would require patches for every imaginable game.

Hardly useful for generic joy->keyboard patch.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« Reply #3 on: May 29, 2006, 01:07:38 PM »
@balrogsoft

You are wrong.

Testing for keypress != generating fake keypresses.

Quote
if i can get a method to simulate the key press at hardware level working with raw key codes, maybe i can make it work.

This is not possible. The only way to do this via software would be to patch all the keyboard routines and spoof fake keyboard events.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« Reply #4 on: May 29, 2006, 03:52:55 PM »
Quote
The method above use input.device to send a key event, then it will depend on how the game capture keyboard events, if it use a system friendly method to capture the keyboard, and it isn't multitask, it will work?

Correct. Any OS friendly apps will capture these events.

This includes:

- input handlers with input.device
- intuition.library IDCMP messages (IDCMP_RAWKEY and IDCMP_VANILLAKEY).
- anything else deriving their keys from the two above

It doesn't include:

- lowlevel.library GetKey() and QueryKeys() (unfortunately GetKey() peeks hw directly and QueryKeys() reads the matrix from keyboard.device directly). These two lowlevel.library functions can be patched, however.
- games/apps reading the keyboard hw directly
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« Reply #5 on: May 29, 2006, 05:20:11 PM »
@Tricky

Can't see how that would help really, as you indeed can't spoof the CIA SDR values. Triggering the int would be possible by just setting the proper intreq flag (iirc, it has been a long long time ;-)).
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« Reply #6 on: May 29, 2006, 08:10:56 PM »
Hm hm, I was fairly sure writing SDR would not work, since I tried to play with this years ago. Ohwell.

Quote
However, how does one invoke the interrupt? Of course we can set the Intreq bit, but where do we set it from?

From the part generating the false events, naturally (joystick movement are turned into key presses and releases).
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« Reply #7 on: May 29, 2006, 10:32:29 PM »
Quote
I less elegant but easier solution may be to use hardware.

hardware solution

/me runs ;-)
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« Reply #8 on: May 30, 2006, 10:34:00 AM »
Quote
when i send an event to keyboard using input.device, it will call keyboard interrupt?

No. Keyboard interrupt only occurs when actual real physical keys are pressed (or keyboard wants to communicate with the rest of the system for some reason).

input.device IND_WRITEEVENT is purely software, it spoofs an input event that is picked up by all input handlers (including that of intuition.library).