Sending keybd_event In-Game [Solved]

Posts 1–15 of 16 · Page 1 of 2
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);


			 }
	};
}
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.
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?
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.
i mean in bfbc2, in the chat box it works. but when not in the chat box it dose not
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...
Try SendMessage, PostMessage and SendInput, one of those might work
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)
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?
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.
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.
Yeah right.

This works fine:

[highlight=c++]numericUpDown1->Value+=1;[/highlight]
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]
ahh Sweet thanks All fixed now
Posts 1–15 of 16 · Page 1 of 2

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?