How can I simulate keyboard commands with software

Discussion in 'Programming' started by seal196565, Nov 25, 2012.

  1. #1
    Can anyone help me. I want to know how I can write a program which will have the same effect on my computer as pressing keys on the keyboard. For example, if I want the program to get the pointer to select the fourth, seventh and twelvth line in any text on the screen. Instead of manually selecting the lines each time I just run my program and it does this automatically? Basically a program that can repeat any sequence of keyboard commands that has been set.
     
    seal196565, Nov 25, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    Pressing a key usually calls a particular section of code in the program. Most of the time, the answer to a question like this is, you don't simulate the keyboard, you just call the code that particular keypress would cause to execute.
     
    Rukbat, Nov 25, 2012 IP
  3. seal196565

    seal196565 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for your reply Rukbat. How would I find out which key presses call up which code lines and how would I call that code and execute it without pressing the key, would this work for mouse movement and left/right clicks as well?
     
    seal196565, Nov 26, 2012 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    By reading the code - there's no other way.

    That would depend on the programming language.

    Yes.
     
    Rukbat, Nov 26, 2012 IP
  5. seal196565

    seal196565 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks a lot for your reply Rukbat, Can you recommend a language that has a lot of predefined commands which can be used to simulate keyboard presses and mouse movement? It would be better if the language was opensource.
     
    seal196565, Nov 26, 2012 IP
  6. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #6
    Sorry, no, that's not how programming works. You have to write the commands - in any programming language.
     
    Rukbat, Nov 26, 2012 IP