i am just trying to send w (forward move button) to battlefield 3 with windows api's Battlefield must be preventing this because in all other programs it works fine but in battlefield it doesn't register is there another way of doing this (NOT MAKING A HACK JUST TO SEE IF IT'S POSSIBLE/FOR FUN) code: Code: Public Class Form1 Const KEYEVENTF_EXTENDEDKEY = &H1 Const KEYEVENTF_KEYUP = &H2 Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Integer Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Integer, ByVal bScan As Integer, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer) Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick If GetAsyncKeyState(Keys.T) Then keybd_event(Keys.W, 0, 0, 0) ' press w keybd_event(Keys.W, 0, KEYEVENTF_KEYUP, 0) ' release w End If End Sub End Class
Cool, very useful for make auto quick-scope for MMOFPS games.. haha. Thanks! C# Code: using Microsoft.VisualBasic; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Runtime.InteropServices; public class Form1 { const KEYEVENTF_EXTENDEDKEY = 0x1; const KEYEVENTF_KEYUP = 0x2; [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] public static extern int GetAsyncKeyState(int vKey); [DllImport("user32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] private static extern void keybd_event(int bVk, int bScan, int dwFlags, int dwExtraInfo); private void Timer1_Tick(object sender, EventArgs e) { if (GetAsyncKeyState(Keys.T)) { keybd_event(Keys.W, 0, 0, 0); // press w keybd_event(Keys.W, 0, KEYEVENTF_KEYUP, 0); // release w } } }
It's because the Game Hack engine that blocks the virtual send keys. Is needed to emulate the keyboard via driver or other thing to really have success on the stroke. I haven't any way on how to do it, but I'll look on it for the way. The code work on other apps or games that haven't virtual keys restrictions. I haven't the sure if it will work, but can inspire you: Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using Microsoft.DirectX; using Microsoft.DirectX.DirectInput; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Device keyboard; keyboard = new Device(SystemGuid.Keyboard); try { keyboard.Acquire(); } catch (DirectXException ex) { Console.WriteLine(ex.Message); } KeyboardState keyboardState; try { keyboard.Poll(); keyboardState = keyboard.GetCurrentKeyboardState(); } catch (NotAcquiredException) { try { keyboard.Acquire(); } catch (InputException iex) { Console.WriteLine(iex.Message); } } catch (InputException ex2) { Console.WriteLine(ex2.Message); } //-------------------------------- Console.WriteLine("Wait 2 seconds:"); Thread.Sleep(2000); } } }
thanks josh i'll look into it, i just needed someone to point me in a direction EDIT: i found some code that i believe will do the trick, but it's in a language i don't understand (it's c++) if anyone could tell me what's going on in it or if they were super kind even port it to vb.net i would love them take a look here Involves a kernel hook