Page 1 of 1

send keys?

Posted: Thu Jun 09, 2005 4:06 am
by doodlemunch
i tried some send key examples but they dont work nice i mean i want to simulate real key presses i can do this with the mouse for example but my idea is to use the keyboard instead of the mouse for my proggy i dont know if visual basics sendkey does this or not but it should i want to simulate not just send a key to a program

Posted: Thu Jun 09, 2005 6:03 am
by Droopy
Try this

Code: Select all

Procedure SendKey(Option.l) 
  ; Author : Oliv
  keybd_event_(Option,0,0,0) ; Simulate Keypress
  keybd_event_(Option,0,#KEYEVENTF_KEYUP,0) ; Simulate release key 
  Delay(60) 
EndProcedure


Delay(5000)
SendKey(#VK_F5)     ; Simulate F5 Keystroke
SendKey(#VK_RETURN) ; Simulate Enter Keystroke

Posted: Thu Jun 09, 2005 8:50 am
by doodlemunch
no it doesnt simulate really a keystroke like if it was passed from the hardware ;(;(;(;(

Re: send keys?

Posted: Thu Jun 09, 2005 9:06 am
by PB
Read this: viewtopic.php?t=4876
And then this: viewtopic.php?t=3766

Posted: Thu Jun 09, 2005 10:09 am
by doodlemunch
thanks :D i read it and compiled all but none simulates a real keystroke
theres many proggys that can tell you when a keys been pressed ((not a keylogger!!!)) but with no snippet it detected a key being pressed looks like its not really simulatingg the keystroke PBs aproach seems the best but it doesnt simulate a real keystroke for what i could see

i thought it was possibel to really really simulate a keystroke i just think im '' not up to the challenge ''

Posted: Thu Jun 09, 2005 12:26 pm
by PB
> PBs aproach seems the best but it doesnt simulate a real keystroke for
> what i could see

My tip/procedure uses the "keybd_event" API which is the native way that
Windows sends keystrokes to the system... so I don't know why you can't
detect them. I use my SendKeys procedure every day, at home and work,
to "type" text into other apps all the time... with no problems whatsoever.

If you want proof, here's an example that simulates keypresses and also
does keylogging of them as they're typed... you can't argue with that! ;)

Code: Select all

If OpenWindow(0,200,200,400,100,#PB_Window_SystemMenu,"Typing Test",0)
  If CreateGadgetList(WindowID())
    TextGadget(0,0,0,400,20,"Click the button to simulate keystrokes!")
    TextGadget(1,0,30,400,20,"Simulated and detected: ")
    ButtonGadget(2,0,60,100,25,"Start typing")
    Repeat
      ev=WaitWindowEvent()
      If ev=#PB_Event_Gadget And EventGadgetID()=2
        SetGadgetText(1,"Simulated and detected: ")
        For a=65 To 90
          ; Next line simulates the keypresses.
          keybd_event_(a,0,0,0) : keybd_event_(a,0,#KEYEVENTF_KEYUP,0)
          If GetAsyncKeyState_(a)<>0 ; This line detects them (keylogger).
            a$=GetGadgetText(1)+Chr(a)
            SetGadgetText(1,a$)
          EndIf
        Next
      EndIf
    Until ev=#PB_Event_CloseWindow
  EndIf
EndIf

Re: send keys?

Posted: Sat May 07, 2022 5:59 am
by marcos.exe
Hi!
I know the post is old, but I would like to know if there is already some way to have a keystroke simulation that actually works well.
All the examples I found on the forum do not work in certain applications, for example, in games running in full screen, or even many in window.
That's exactly what I needed an effective code for.

Original.

Oi!
Eu sei que o post é antigo, mas eu gostaria de saber se já existe alguma forma de ter uma simulação de pressionamento de teclas que realmente funcione bem.
Todos os exemplos que encontrei no forum não funciona em determinados aplicativos, como por exemplo, em jogos executados em tela cheia, ou até mesmo muitos em janela.
Era justamente para isso que precisava de um código eficaz.

Re: send keys?

Posted: Sat May 07, 2022 6:44 am
by BarryG
Hi, which games doesn't it work with? I'm able to use keybd_event_() with a few full-screen games that I just tried. Or which windowed app doesn't it work with?

Re: send keys?

Posted: Sat May 07, 2022 9:51 am
by AZJIO

Re: send keys?

Posted: Sat May 07, 2022 7:15 pm
by marcos.exe
Does not work with mame emulator.
SendInput doesn't either.
I'm trying PureAutoIt, but not even the example scripts that come with the package are working in this version of PureBasic.

Re: send keys?

Posted: Sun May 08, 2022 2:33 am
by BarryG
marcos.exe wrote: Sat May 07, 2022 7:15 pmDoes not work with mame emulator
MAME is a special case that ignores them -> http://forum.arcadecontrols.com/index.p ... 95616.html

Re: send keys?

Posted: Mon May 09, 2022 3:58 pm
by marcos.exe
Well, according to what I could find about MAME, is that those who know how to do it, do not that, due to malicious users.
Programmers are encouraged to send joystick buttons. I have no idea how to do this.

I used an old MAME emulator that runs on the command line (v.0.79), and the keystroke works fine.
I noticed that the most current versions of MAME, or at least the MAME32 ones, didn't work.
I tested it with some less current ones like 0.100 which was the lowest, and it doesn't work.

It was then that I discovered that the developers made it clear that no future version of MAME will be able to allow this feature, as a security measure, to prevent illegal cabinet owners from creating something prohibited. I didn't quite understand. But...

They developed a plugin to do what I intended, but I haven't tested it yet.
https://docs.mamedev.org/plugins/inputmacro.html

As for the scripts I made, they work on the version I mentioned at the beginning, and on gens, which is a Genesis/MegaDrive emulator.
I haven't tested it with other emulators, but I already know that if it doesn't work, it could be for the same reason as the MAME developers.

OK. It must be done, what needs to be done.

Thank you all for your help.