Sign in to follow this  
BlueBolt

Unity Simulating keypresses?

Recommended Posts

Hi to the entire GameDev community... I wondering if there is any method by which I can simulate keypresses in a C++ program? The program is intended for use on Win32 platform, although I'ld like to know the possibilities for other OSs too, if possible. -regards, BlueBolt

Share this post


Link to post
Share on other sites
One possible solution is with buffered input.

By storing the state of each key, you can have a GetKeyState
method to return the status of a key in the buffer.

Because the keys in the buffer or stored in the program, it is
very easy to modify the buffer (changing the status of a key)

Under Windows, you can use the GetKeyboardState to retrieve the current state of all keys,
and SetKeyState to set the programs keyboard state table directly.

You can also try SendInput

Hope this helps!

Share this post


Link to post
Share on other sites
the HWND is for the window you are trying to click in. mx and my are mouse positions in the windows geometry. this works for clicks in your program and for other programs you might want to sent clicks to.


void MouseClick( HWND hwnd, int mx, int my )
{
SetCursorPos( mx, my ); // needed for SUN JavaVM windows
Sleep( 10 ); // give time for cursor to move

LPARAM pt = my;

pt <<= 16;
pt += mx;

::PostMessage( hwnd, WM_LBUTTONDOWN, MK_LBUTTON, pt );

Sleep( 10 ); // time between mouse down and up

::PostMessage( hwnd, WM_LBUTTONUP, 0, pt );
}



Share this post


Link to post
Share on other sites
(O.O Wow, this is big league stuff! xD)
Thanks, Mr Crypter and Mr Spurious! I'll start learning these right away, they're quite advanced for me.
Thanks again! ^_^
-regards,
BlueBolt

Share this post


Link to post
Share on other sites
if youre looking to run somthing outside of the program that simulates input. take a look at AutoIt. it's a scripter that can read the screen and simulate mouse/keyboard input.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Announcements

  • Forum Statistics

    • Total Topics
      628356
    • Total Posts
      2982252
  • Similar Content

    • By koto
      Hello,

      I'm developing a roguelike game. Currently it's in a playable state and I think it's a high time to show it and hopefully get some feedback.

      The game has following features:
      - turn based
      - procedurally generated levels
      - tons of loot
      - spells system
      - trading system
      - some quests
      - some limited crafting
      - door/key/lever mechanics
      - quite a lot of different (look/behaviour) monsters

      Trailer:
      Demo: http://kotogames.com/wp-content/uploads/2017/11/OuaD_demo.zip
      Regards,
      Tom
       
    • By Afambus
      Hello,
      I have a full experienced team that looking for a composer and another 3d designer, im expecting as much from you there are other people in this server that can help you we have a determined team, we have done many things in our game there is more information in the discord about everyone and there skills there region and about the game, if you join the discord pm asap
      https://discord.gg/b2teN3m
    • By BAG Labs
      Mobile SoS

      Platform: Android
      Genre: Board
      Link: Google Play
       
      This games sharpen memory and test your strategies to place S-O-S pattern within time limit and serve 3 difficulties as Easy, Normal, and Hard.

      Goals of the game is to put S-O-S words in patterns (Horizontal, Vertical, and Diagonal) alternately with enemy.
       
      Features:
      Single Player Multiplayer Achievements Leaderboards  
       
      Screenshot:

       

       

       
      Link: Google Play
       
      Please help us improve this game with review
    • By abarnes
      Hello!
      I am a game development student in my second year of a three year program and I would like to start building my portfolio. I was thinking of creating some games to show what I can do to potential employers since I wont have any work related experience when I graduate. But as I'm sure you all know there are tons of ways to approach developing/designing a game and I'm curious if anyone had any insight as to any "standards" that come with this? Is it okay to use game engines like Unity, Unreal, Game Maker etc? Or would it be better to make a game from scratch to better show case your skills? Any and all advice will be greatly appreciated!
    • By Hilster
      Hello 2D Artists,
      I've started making a 2D Puzzle Adventure game for mobile and I'm looking for someone who would want in on creating assets for the game. The core of the programming is pretty much complete, you can walk within the grid laid out and push boxes, when there is an object on top of a pressure pad it will activate the linked objects or if there is one object with multiple linked pressure pads it requires you to activate all points for the object to become active. 

      The level iteration for the game is quick and simple, a Photoshop file that is made of individual pixels that represents objects is put into the game and it creates the level out of those pixels with the assigned objects.
      The objects that need sprites created so far is the character, box, pressure pad, door, trap door, the walls, the stairs and the tiled background.
      I intend to add more objects so the amount I'd like to add will be extended.
      My motivations for posting here is to have something that looks nice to be able to display on my portfolio, so if you're looking for a working game that you can place your art into and improve the look of your portfolio then we're in business.
      Please reply with a few past examples of your art below and I'll be in touch!
  • Popular Now