Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    tester181's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Posts
    34
    Reputation
    10
    Thanks
    14

    Sending keybd_event In-Game [Solved]

    hey i new to c++.. been using Vb for 5 maby 6 years lols..... any ways

    im trying to send "space bar" the keypress using "keybd_event"
    in Bfbc2. when i press the button to send it, it dose not do it ingame but out of it. would i need to hook it? maby a API hook or some thing?

    a lil tut would be amazing if poss.
    my code atm...

    i want to get this to work so i can make any gun have a 3 round Burst. or longer. im guessing this would be easy for you guys to help me out
    and yeah i know typo with swndkeys lol

    Thanks Guys!


    Code:
    #pragma once
    
    #include <windows.h>
    //#include <User32.lib> 
    #pragma comment(lib,"User32.lib")
    SDKs\Windows\v7.0A\Lib\User32.lib>
    namespace Swndkeys {
    
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    
    	/// <summary>
    	/// Summary for Form1
    	///
    	/// WARNING: If you change the name of this class, you will need to change the
    	///          'Resource File Name' property for the managed resource compiler tool
    	///          associated with all .resx files this class depends on.  Otherwise,
    	///          the designers will not be able to interact properly with localized
    	///          resources associated with this form.
    	/// </summary>
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Add the constructor code here
    			//
    		}
    
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Button^  button1;
    	protected: 
    
    	private:
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		System::ComponentModel::Container ^components;
    
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(13, 13);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(75, 23);
    			this->button1->TabIndex = 0;
    			this->button1->Text = L"button1";
    			this->button1->UseVisualStyleBackColor = true;
    			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(284, 262);
    			this->Controls->Add(this->button1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->ResumeLayout(false);
    
    		}
    #pragma endregion
    	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    ::Sleep(6000);
     keybd_event(VK_MENU, 0x36, 0, 0);
      keybd_event(VK_SPACE, 0, 0, 0);
    
      ::Sleep(1000);
    
      // stop pressing "Alt-Tab"
    
      keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
      keybd_event(VK_SPACE, 0, KEYEVENTF_KEYUP, 0);
    
    
    			 }
    	};
    }

  2. #2
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    That is because your application gets the focus instead of the game. So, your program sends the keys to itself. To solve this, use a timer and put the code in it. But, surround the code in an if statement that checks whether a particular key is being pressed.

    Here's a rough idea:

    [highlight=c++]#include "stdafx.h"

    #define IsKeyDown(Key) GetAsyncKeyState(Key) & 0x8000 //Used to check if a key is down.

    void YourTimer(Parameters...)
    {
    if (IsKeyDown(VK_SPACE))
    {
    ::Sleep(6000);
    keybd_event(VK_MENU, 0x36, 0, 0);
    keybd_event(VK_SPACE, 0, 0, 0);

    ::Sleep(1000);

    // stop pressing "Alt-Tab"

    keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_SPACE, 0, KEYEVENTF_KEYUP, 0);
    }

    }[/highlight]

    Hope, this gives you the idea.

  3. #3
    tester181's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Posts
    34
    Reputation
    10
    Thanks
    14
    hmm kk thanks, just tryed that and it dose not want to work. i thought i needed to hook it? as its had directx?, it works in minecraft...

    edit:

    hmm changed one thing.. testing

    Edit2:

    it works in chat but, not when ingame for example if i type "iiiiiiiiiiiiiii" into chat to check if it work it will so it would look like"iiiiiiiii iii"
    but it will not make me jump?
    Last edited by tester181; 09-26-2011 at 11:24 AM.

  4. #4
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by tester181 View Post
    hmm kk thanks, just tryed that and it dose not want to work. i thought i needed to hook it? as its had directx?, it works in minecraft...

    edit:

    hmm changed one thing.. testing

    Edit2:

    it works in chat but, not when ingame for example if i type "iiiiiiiiiiiiiii" into chat to check if it work it will so it would look like"iiiiiiiii iii"
    but it will not make me jump?
    Maybe you need to set the focus to the game itself, which is set the the chat box at the moment ?

    Check which key loses the focus to chat and then send that key to the game before trying to send keys that make the jump happen.

  5. #5
    tester181's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Posts
    34
    Reputation
    10
    Thanks
    14
    i mean in bfbc2, in the chat box it works. but when not in the chat box it dose not

  6. #6
    KissU's Avatar
    Join Date
    Oct 2010
    Gender
    male
    Posts
    107
    Reputation
    10
    Thanks
    14
    My Mood
    Blah
    Sorry for my dumbish but wich game is bfbc2,and it have some protection like xtrap,gameguard? Maybe you need a bypass.
    ~EDIT
    I've searched and its Battlefield Bad Company 2 but if it have protection I dont know,cuz I play wolfteam and guameguard block auto-clickers,blah blah blah...
    Last edited by KissU; 09-26-2011 at 01:16 PM.

  7. #7
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Try SendMessage, PostMessage and SendInput, one of those might work
    Ah we-a blaze the fyah, make it bun dem!

  8. #8
    tester181's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Posts
    34
    Reputation
    10
    Thanks
    14
    iv found out how to do it , thanks for the help guys.. just cleaning it up now.. another question

    how do i point the sleep Delay to numericupandown1?

    this dose not work
    Sleep(NumericUpDown1->Value);

    or
    Sleep(NumericUpDown1.Value);


    edit:
    vb.net is
    Sleep(NumericUpDown1.Value)
    Last edited by tester181; 09-26-2011 at 04:22 PM.

  9. #9
    Nico's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    Germany :D
    Posts
    15,918
    Reputation
    1121
    Thanks
    8,617
    Quote Originally Posted by tester181 View Post
    iv found out how to do it , thanks for the help guys.. just cleaning it up now.. another question

    how do i point the sleep Delay to numericupandown1?

    this dose not work
    Sleep(NumericUpDown1->Value);

    or
    Sleep(NumericUpDown1.Value);


    edit:
    vb.net is
    Sleep(NumericUpDown1.Value)
    Could you maybe tell us what NumericUpDown1 is?

  10. #10
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by tester181 View Post
    iv found out how to do it , thanks for the help guys.. just cleaning it up now.. another question

    how do i point the sleep Delay to numericupandown1?

    this dose not work
    Sleep(NumericUpDown1->Value);

    or
    Sleep(NumericUpDown1.Value);


    edit:
    vb.net is
    Sleep(NumericUpDown1.Value)
    Sleep(NumericUpDown1::Value);

    + Marked Solved.

  11. #11
    tester181's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Posts
    34
    Reputation
    10
    Thanks
    14
    ahh thanks after a few tweeks will post for peeps to use

    edit:


    with that i get a new error

    error C2653: 'NumericUpDown1' : is not a class or namespace name

    i was reading up and some one said it could be the order of the "#include"?

    if so this is what it is:
    Code:
    #pragma once
    #include <cstdlib>
    #include "stdafx.h"
    //#include <isostream>
    #include <windows.h>
    //#include <User32.lib> 
    #pragma comment(lib,"User32.lib")
    //#include <F:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\User32.lib>
    
    bool switch1;
     
    
     
    #define IsKeyDown(Key) GetAsyncKeyState(Key) & 0x8000 //Used to check if a key is down.
    Last edited by tester181; 09-27-2011 at 11:37 AM.

  12. #12
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Yeah right.

    This works fine:

    [highlight=c++]numericUpDown1->Value+=1;[/highlight]

  13. #13
    tester181's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Posts
    34
    Reputation
    10
    Thanks
    14
    im trying to get sleep to read the Milliseconds from a Value box on the form so that wont work :S

    Edit
    NumericUpDown1 is



    https://imageshack.us/f/841/1123b.png/
    Last edited by tester181; 09-27-2011 at 12:45 PM.

  14. #14
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by tester181 View Post
    im trying to get sleep to read the Milliseconds from a Value box on the form so that wont work :S

    Edit
    NumericUpDown1 is



    Imageshack - 1123b.png
    That is because Value is of type decimal and since CLI is strict about type conversion, you need to convert it to Integer so Sleep function can take it.

    [highlight=c++]System::Threading::Thread::Sleep(Convert::ToInt32( numericUpDown1->Value));[/highlight]

  15. #15
    tester181's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Posts
    34
    Reputation
    10
    Thanks
    14
    ahh Sweet thanks All fixed now

Page 1 of 2 12 LastLast

Similar Threads

  1. help me plz cant start game[SOLVED]
    By zombiedick in forum CrossFire Help
    Replies: 7
    Last Post: 08-12-2010, 01:13 AM
  2. The Hack Disappears When i START THE GAME[SOLVED]
    By TheLeader2 in forum CrossFire Help
    Replies: 9
    Last Post: 08-07-2010, 09:41 AM
  3. [SOLVED] Program for all title in game
    By ahou in forum Call of Duty Modern Warfare 2 Help
    Replies: 5
    Last Post: 06-10-2010, 03:07 AM
  4. Problem in game[Solved]
    By amitbachar12 in forum Combat Arms EU Discussions
    Replies: 8
    Last Post: 03-15-2010, 02:47 PM