Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Is there any way to simulate a keyboard press button?

Author
Message
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 26th Mar 2011 13:09
Hi ,

I would like to simulate a keyboard press button when I am pressing one interface button.

For example , I have navigation button keys in my interface and when I pressing the navigation button on my interface , I would like to simulate one keypress.

As I know keystate(72) checks if the up arrow is pressed.
Is any way to simulate this keystate without pressing the up arrow on my keyboard?

This could be good to have a quide or automatic follow someone NPC player for example...

Thank you....
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 26th Mar 2011 13:44 Edited at: 26th Mar 2011 13:48
You could try inkey$() for checking certain keypresses.
However the arrow keys have different commands just for them.

Such as:

Upkey()
Downkey() etc

So you could write:

If upkey() = 1 `check if upkey is being pressed
Do Something
EndIf

Im not sure 100% what you mean but hopefully this helps.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 26th Mar 2011 15:00
I'm not sure how you could directly simulate a keypress, but since you're in control of what that keypress does you could always just add another condition that causes the same effect as the keypress. For example, say you had this:

If Keystate(72)
Move Object 1,5
Endif

If you wanted you could make a variable called FakeUpArrow which would tell when you were "simulating" the key press. Then, you'd simply add this new variable like this:

If Keystate(72) or FakeUpArrow=1
Move Object 1,5
Endif

With this in place you'd simply set FakeUpArrow equal to 1 whenever you wanted to simulate an up arrow key press, and set it back to 0 when you didn't want the up arrow key to be pressed.


Guns, cinematics, stealth, items and more!
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 26th Mar 2011 19:29 Edited at: 26th Mar 2011 19:32
You can do it using User32.dll. I put together this quick test code to demonstrate:
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 26th Mar 2011 22:23 Edited at: 27th Mar 2011 02:51
Thank you very very much , your idea helped me a lot.
I made the function and now I can simulate keyboard press.

I have a small demo what I have create so far.

http://www.sendspace.com/file/g2io2w

I made it with fake variables , the user32.dll functions , seems very difficult to me.

But thank you , is good for knowledge...
I don't know what are the (APIs) for all keyboard buttons not only "a" and "b"

revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 28th Mar 2011 08:27
Quote: "don't know what are the (APIs) for all keyboard buttons not only "a" and "b""
That leads me to believe that you didn't read the comments in my code snippet...
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 2nd Jul 2011 01:34
Yes , I didn't visit the websites you have in comments.
So now I visited the websites and I will use your code in my game.

Thank you very much. I am looking for fast arrays , or dynamic arrays , I will try to change my code a little.
Bulsatar
13
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 8th Jul 2011 07:11
With using the User32.dll...does this mean that it is possible to use os function calls natively in darkbasic pro?
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 5th Sep 2011 18:24
I didn't used the api call yet , but "revenant chaos" have the code you are able to use the User32.dll.

Virtual-Key Codes: http://msdn.microsoft.com/en-us/library/ms645540

Login to post a reply

Server time is: 2024-11-22 16:31:48
Your offset time is: 2024-11-22 16:31:48