Welcome, Guest. Please login or register.

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

Description:

0 Members and 1 Guest are viewing this topic.

Offline balrogsoftTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2006
  • Posts: 186
    • Show only replies by balrogsoft
    • http://www.amigaskoolnet
Simulate key press, help need.
« on: May 29, 2006, 12:40:57 AM »
 Hi, i saw a interesting page with all games that support 4 player adaptor, and i have a idea that i don't know if it can work.

 I played with Blitz Basic 2 and my new 4 players adaptor on my Amiga 600, i made some asm functions to read player 3 and 4 joysticks, and it work perfectly, i used an asm example on aminet.

 Some games have options to play with 4 players, 2 players on joystick and 2 players on keyboard, i want to make a program that redirect player 3 and 4 joysticks to Amiga keyboard, then a lot of games will be able to use the 4 players adaptor. I only made small asm programs some years ago, i have some Amiga programming books, but i don't find a way to simulate a key press event, exist a method to make it work? and for no-multitask games also? somebody knows how to make it in assembler?
Balrog Software · http://www.amigaskool.net
Mac Mini G4 1,5ghz · MorphOS 2.7 · Ati Radeon 9200 64Mb · 1 Gb RAM · 80 GB HD
Efika · MorphOS 2.7 · Ati Radeon 9250 128Mb · 120 Gb WD HD
Amiga 1200T · OS 3.9 · Voodoo3 · Blizzard 603e/240mhz 060/50mhz · 98 Mb RAM · 40 GB HD
Amiga 600 · OS 3.1 · ACA 630/25mhz 32 Mb RAM · 4Gb CF
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« Reply #1 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 balrogsoftTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2006
  • Posts: 186
    • Show only replies by balrogsoft
    • http://www.amigaskoolnet
Re: Simulate key press, help need.
« Reply #2 on: May 29, 2006, 09:34:33 AM »
Thanks a lot, Piru! I think that exist a way to make it work with no multitasking games, but this piece of code can be usefull. I will try after work and will see how many games will work with it. There is a site where i can download Amiga include files for assembler? i found a web with AsmOne but it don't have includes.
Balrog Software · http://www.amigaskool.net
Mac Mini G4 1,5ghz · MorphOS 2.7 · Ati Radeon 9200 64Mb · 1 Gb RAM · 80 GB HD
Efika · MorphOS 2.7 · Ati Radeon 9250 128Mb · 120 Gb WD HD
Amiga 1200T · OS 3.9 · Voodoo3 · Blizzard 603e/240mhz 060/50mhz · 98 Mb RAM · 40 GB HD
Amiga 600 · OS 3.1 · ACA 630/25mhz 32 Mb RAM · 4Gb CF
 

Offline orange

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show only replies by orange
Re: Simulate key press, help need.
« Reply #3 on: May 29, 2006, 11:32:34 AM »
I think you should contact those guys that make whdload game loaders. Ask them how they made for eg. F10 exit the game. But its probably veeery difficult and time consuming disassembling nondos games..
Better sorry than worry.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« Reply #4 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 only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« Reply #5 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 balrogsoftTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2006
  • Posts: 186
    • Show only replies by balrogsoft
    • http://www.amigaskoolnet
Re: Simulate key press, help need.
« Reply #6 on: May 29, 2006, 12:43:08 PM »
Quote

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

Hardly useful for generic joy->keyboard patch.


Different but not at all, WHDLoad execute a routine to test F10 key on non multitasking games, maybe it will not work with the code above because it is working on OS level, 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. Correct me if i'm wrong...
Balrog Software · http://www.amigaskool.net
Mac Mini G4 1,5ghz · MorphOS 2.7 · Ati Radeon 9200 64Mb · 1 Gb RAM · 80 GB HD
Efika · MorphOS 2.7 · Ati Radeon 9250 128Mb · 120 Gb WD HD
Amiga 1200T · OS 3.9 · Voodoo3 · Blizzard 603e/240mhz 060/50mhz · 98 Mb RAM · 40 GB HD
Amiga 600 · OS 3.1 · ACA 630/25mhz 32 Mb RAM · 4Gb CF
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« Reply #7 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 xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show only replies by xeron
    • http://www.petergordon.org.uk
Re: Simulate key press, help need.
« Reply #8 on: May 29, 2006, 01:41:30 PM »
Modifying non-OS friendly games to insert fake keys into their input queue would require as much effort as just adding four player adaptor support directly into the game code.
Playstation Network ID: xeron6
 

Offline balrogsoftTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2006
  • Posts: 186
    • Show only replies by balrogsoft
    • http://www.amigaskoolnet
Re: Simulate key press, help need.
« Reply #9 on: May 29, 2006, 02:13:39 PM »
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?
Balrog Software · http://www.amigaskool.net
Mac Mini G4 1,5ghz · MorphOS 2.7 · Ati Radeon 9200 64Mb · 1 Gb RAM · 80 GB HD
Efika · MorphOS 2.7 · Ati Radeon 9250 128Mb · 120 Gb WD HD
Amiga 1200T · OS 3.9 · Voodoo3 · Blizzard 603e/240mhz 060/50mhz · 98 Mb RAM · 40 GB HD
Amiga 600 · OS 3.1 · ACA 630/25mhz 32 Mb RAM · 4Gb CF
 

Offline motorollin

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show only replies by motorollin
Re: Simulate key press, help need.
« Reply #10 on: May 29, 2006, 02:25:36 PM »
This would only work of the game uses input.device...

--
moto
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« Reply #11 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 Tricky

  • Full Member
  • ***
  • Join Date: Aug 2005
  • Posts: 127
    • Show only replies by Tricky
    • http://www.jigsawlounge.co.uk/kungfu/
Re: Simulate key press, help need.
« Reply #12 on: May 29, 2006, 04:25:34 PM »
I guess you could patch the Keyboard interrupt.  A lot of non-multitasking games probably still use this, as it's the best fool-proof way to get keyboard input.  But of course that is only triggered when a key is actually pressed.  Any other interrupt, e.g. vertical blank, is liable to be turned off or replaced.

It also means writing to the CIA Serial Data Register ($BFEC01) directly, not sure how well that would work, if at all.
[A1200/060, 32Mb fast RAM, 1.2Gb HDD, 19\\" Acer TFT Monitor]
I never write anything that won\\\'t run on a stock A1200.  That\\\'s the Jigsaw Lounge Guarantee.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Simulate key press, help need.
« Reply #13 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 Tricky

  • Full Member
  • ***
  • Join Date: Aug 2005
  • Posts: 127
    • Show only replies by Tricky
    • http://www.jigsawlounge.co.uk/kungfu/
Re: Simulate key press, help need.
« Reply #14 on: May 29, 2006, 06:47:43 PM »
@Piru

You can write to the SDR, and it will stay as written until the next keypress.  (I just tried it.)  So doing that before exiting the interrupt should spoof a keypress.

However, how does one invoke the interrupt?  Of course we can set the Intreq bit, but where do we set it from?  If we set it from the keyboard interrupt server, the computer will never execute anything other than that interrupt!
[A1200/060, 32Mb fast RAM, 1.2Gb HDD, 19\\" Acer TFT Monitor]
I never write anything that won\\\'t run on a stock A1200.  That\\\'s the Jigsaw Lounge Guarantee.