Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 21:56

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Send Function key to a game

Discussion on Send Function key to a game within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
Ell0ll's Avatar
 
elite*gold: 0
Join Date: Jan 2013
Posts: 5
Received Thanks: 0
Question Send Function key to a game

Hello every one

i have tried this code and did not work

Code:
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As UInteger, ByVal dwExtraInfo As UInteger)
    Const KEYEVENTF_KEYUP = &H2

    <DllImport("user32.dll", SetLastError:=True)> _
    Private Shared Function GetForegroundWindow() As IntPtr
    End Function

    <DllImport("user32.dll", SetLastError:=True)> _
    Private Shared Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, _
                      ByRef lpdwProcessId As Integer) As Integer
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Timer1.Enabled = True

    End Sub

    Private Sub press(ByVal mykey As Keys)

        keybd_event(CByte(mykey), 0, 0, 0)
        keybd_event(CByte(mykey), 0, KEYEVENTF_KEYUP, 0)

    End Sub

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick

       
        Dim fgWin = GetForegroundWindow()
        Dim fgPid As New Integer()
        GetWindowThreadProcessId(fgWin, fgPid)

        Dim proc = System.Diagnostics.Process.GetProcessById(fgPid)

        If (proc.ProcessName = "bout.dat") Then
           
            press(Keys.F8)

        End If

    End Sub
also i have tried this code and did not work too

Code:
Imports System.Runtime.InteropServices

Public NotInheritable Class InputHelper
    Private Sub New()
    End Sub

#Region "Methods"
#Region "PressKey()"
    ''' <summary>
    ''' Virtually presses a key.
    ''' </summary>
    ''' <param name="Key">The key to press.</param>
    ''' <param name="HardwareKey">Whether or not to press the key using its hardware scan code.</param>
    ''' <remarks></remarks>
    Public Shared Sub PressKey(ByVal Key As Keys, Optional ByVal HardwareKey As Boolean = False)
        If HardwareKey = False Then
            InputHelper.SetKeyState(Key, False)
            InputHelper.SetKeyState(Key, True)
        Else
            InputHelper.SetHardwareKeyState(Key, False)
            InputHelper.SetHardwareKeyState(Key, True)
        End If
    End Sub
#End Region

#Region "SetKeyState()"
    ''' <summary>
    ''' Virtually sends a key event.
    ''' </summary>
    ''' <param name="Key">The key of the event to send.</param>
    ''' <param name="KeyUp">Whether to push down or release the key.</param>
    ''' <remarks></remarks>
    Public Shared Sub SetKeyState(ByVal Key As Keys, ByVal KeyUp As Boolean)
        Key = ReplaceBadKeys(Key)

        Dim KeyboardInput As New KEYBDINPUT With {
            .wVk = Key,
            .wScan = 0,
            .time = 0,
            .dwFlags = If(KeyUp, KEYEVENTF.KEYUP, 0),
            .dwExtraInfo = IntPtr.Zero
        }

        Dim Union As New INPUTUNION With {.ki = KeyboardInput}
        Dim Input As New INPUT With {
            .type = INPUTTYPE.KEYBOARD,
            .U = Union
        }

        SendInput(1, New INPUT() {Input}, Marshal.SizeOf(GetType(INPUT)))
    End Sub
#End Region

#Region "SetHardwareKeyState()"
    ''' <summary>
    ''' Virtually sends a key event using the key's scan code.
    ''' </summary>
    ''' <param name="Key">The key of the event to send.</param>
    ''' <param name="KeyUp">Whether to push down or release the key.</param>
    ''' <remarks></remarks>
    Public Shared Sub SetHardwareKeyState(ByVal Key As Keys, ByVal KeyUp As Boolean)
        Key = ReplaceBadKeys(Key)

        Dim KeyboardInput As New KEYBDINPUT With {
            .wVk = 0,
            .wScan = MapVirtualKeyEx(CUInt(Key), 0, GetKeyboardLayout(0)),
            .time = 0,
            .dwFlags = KEYEVENTF.SCANCODE Or If(KeyUp, KEYEVENTF.KEYUP, 0),
            .dwExtraInfo = IntPtr.Zero
        }

        Dim Union As New INPUTUNION With {.ki = KeyboardInput}
        Dim Input As New INPUT With {
            .type = INPUTTYPE.KEYBOARD,
            .U = Union
        }

        SendInput(1, New INPUT() {Input}, Marshal.SizeOf(GetType(INPUT)))
    End Sub
#End Region

#Region "ReplaceBadKeys()"
    ''' <summary>
    ''' Replaces bad keys with their corresponding VK_* value.
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared Function ReplaceBadKeys(ByVal Key As Keys) As Keys
        Dim ReturnValue As Keys = Key

        If ReturnValue.HasFlag(Keys.Control) Then
            ReturnValue = (ReturnValue And Not Keys.Control) Or Keys.ControlKey 'Replace Keys.Control with Keys.ControlKey.
        End If

        If ReturnValue.HasFlag(Keys.Shift) Then
            ReturnValue = (ReturnValue And Not Keys.Shift) Or Keys.ShiftKey 'Replace Keys.Shift with Keys.ShiftKey.
        End If

        If ReturnValue.HasFlag(Keys.Alt) Then
            ReturnValue = (ReturnValue And Not Keys.Alt) Or Keys.Menu 'Replace Keys.Alt with Keys.Menu.
        End If

        Return ReturnValue
    End Function
#End Region
#End Region

#Region "WinAPI P/Invokes"
    <DllImport("user32.dll", SetLastError:=True)>
    Private Shared Function SendInput(ByVal nInputs As UInteger, <MarshalAs(UnmanagedType.LPArray)> ByVal pInputs() As INPUT, ByVal cbSize As Integer) As UInteger
    End Function

    <DllImport("user32.dll")> _
    Private Shared Function MapVirtualKeyEx(uCode As UInteger, uMapType As UInteger, dwhkl As IntPtr) As UInteger
    End Function

    <DllImport("user32.dll")> _
    Private Shared Function GetKeyboardLayout(idThread As UInteger) As IntPtr
    End Function

#Region "Enumerations"
    Private Enum INPUTTYPE As UInteger
        MOUSE = 0
        KEYBOARD = 1
        HARDWARE = 2
    End Enum

    <Flags()> _
    Private Enum KEYEVENTF As UInteger
        EXTENDEDKEY = &H1
        KEYUP = &H2
        SCANCODE = &H8
        UNICODE = &H4
    End Enum
#End Region

#Region "Structures"
    <StructLayout(LayoutKind.Explicit)> _
    Private Structure INPUTUNION
        <FieldOffset(0)> Public mi As MOUSEINPUT
        <FieldOffset(0)> Public ki As KEYBDINPUT
        <FieldOffset(0)> Public hi As HARDWAREINPUT
    End Structure

    Private Structure INPUT
        Public type As Integer
        Public U As INPUTUNION
    End Structure

    Private Structure MOUSEINPUT
        Public dx As Integer
        Public dy As Integer
        Public mouseData As Integer
        Public dwFlags As Integer
        Public time As Integer
        Public dwExtraInfo As IntPtr
    End Structure

    Private Structure KEYBDINPUT
        Public wVk As UShort
        Public wScan As Short
        Public dwFlags As UInteger
        Public time As Integer
        Public dwExtraInfo As IntPtr
    End Structure

    Private Structure HARDWAREINPUT
        Public uMsg As Integer
        Public wParamL As Short
        Public wParamH As Short
    End Structure
#End Region
#End Region



End Class
Code:
 Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
       
        Dim fgWin = GetForegroundWindow()
        Dim fgPid As New Integer()
        GetWindowThreadProcessId(fgWin, fgPid)

        Dim proc = System.Diagnostics.Process.GetProcessById(fgPid)

        If (proc.ProcessName = "bout.dat") Then
           
            InputHelper.PressKey(Keys.F8, True)

        End If

    End Sub
if i send letters or numbers both are working with no problems but not Function keys

to make sure i have tried windows 7 On screen keyboard it can send Function keys
also i tried some free virtual keyboard all can send numbers and letters but not Function keys

except This it is like windows 7 OSK both can send Function keys to the game

sorry for this long story but i want it to be clear

My question : is there any code (VB2010) that can send Function keys to the game like windows 7 OSK ?

Also : Why Windows 7 OSK and >>> can send Function keys to the game and there are some other free virtual keyboard can't send Function keys

>>> which code are using to make it work

I hope some can do it
Ell0ll is offline  
Old 09/17/2017, 13:07   #2

 
EasyFarm's Avatar
 
elite*gold: 281
Join Date: May 2011
Posts: 1,553
Received Thanks: 947
Maybe your game is using dinput, so your way won't work like this ^^
EasyFarm is offline  
Old 09/18/2017, 19:49   #3
 
Ploxasarus's Avatar
 
elite*gold: 193
Join Date: Jan 2008
Posts: 2,656
Received Thanks: 2,449
This is C# but should be helpful.


Code:
        [DllImport("user32.dll", SetLastError = true)]
        private static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

private void Timer1_Tick(object sender, EventArgs e)
       
            const int WM_KEYDOWN = 0x100;
            const int WM_KEYUP = 0x101;

            string processName = "bout.dat";
            Process[] processList = Process.GetProcesses();

            foreach (Process p in processList)
            {
                if (p.ProcessName.Equals(processName))
                {
                    IntPtr hWnd = p.MainWindowHandle;
                    PostMessage(hWnd, WM_KEYDOWN, 0x77, 0x420001);
                    Thread.Sleep(2);
                    PostMessage(hWnd, WM_KEYUP, 0x77, 0x420001);
                }
            }
        }
Ploxasarus is offline  
Old 09/19/2017, 01:30   #4
 
Ell0ll's Avatar
 
elite*gold: 0
Join Date: Jan 2013
Posts: 5
Received Thanks: 0
Quote:
Originally Posted by Ploxasarus View Post
This is C# but should be helpful.


Code:
        [DllImport("user32.dll", SetLastError = true)]
        private static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

private void Timer1_Tick(object sender, EventArgs e)
       
            const int WM_KEYDOWN = 0x100;
            const int WM_KEYUP = 0x101;

            string processName = "bout.dat";
            Process[] processList = Process.GetProcesses();

            foreach (Process p in processList)
            {
                if (p.ProcessName.Equals(processName))
                {
                    IntPtr hWnd = p.MainWindowHandle;
                    PostMessage(hWnd, WM_KEYDOWN, 0x77, 0x420001);
                    Thread.Sleep(2);
                    PostMessage(hWnd, WM_KEYUP, 0x77, 0x420001);
                }
            }
        }
i have tried it - it is not working

Quote:
Originally Posted by EasyFarm View Post
Maybe your game is using dinput, so your way won't work like this ^^
what is the solution for it ?

Game for any one want try it
Ell0ll is offline  
Old 09/20/2017, 14:03   #5
 
killzone's Avatar
 
elite*gold: 100
Join Date: Mar 2006
Posts: 1,826
Received Thanks: 430
Look into VK_Keys. Its what I used automating directX games.

It appears, I already answered you on ****.
killzone is offline  
Old 10/08/2017, 20:04   #6
 
Kurisu Makise's Avatar
 
elite*gold: 0
Join Date: Dec 2016
Posts: 22
Received Thanks: 4
Quote:
Originally Posted by Xio. View Post


That's what I'm using to send keystrokes to games. It's working. Don't tell me it isn't, I'm using it.
its not working for me .. >.<
Kurisu Makise is offline  
Thanks
1 User
Old 10/09/2017, 23:20   #7
 
Kurisu Makise's Avatar
 
elite*gold: 0
Join Date: Dec 2016
Posts: 22
Received Thanks: 4
Quote:
Originally Posted by Xio. View Post
run your app as admin... jesus ******* christ.
I ran it as admin but its not working! -.- satan ******* christ.
Kurisu Makise is offline  
Old 10/10/2017, 19:08   #8
 
Kurisu Makise's Avatar
 
elite*gold: 0
Join Date: Dec 2016
Posts: 22
Received Thanks: 4
Quote:
Originally Posted by Xio. View Post
works for OP. Better go learn how to use google
just because i works for op it doesnt mean it runs for everyone. better go learn how to use your brain instead of google
Kurisu Makise is offline  
Old 10/10/2017, 21:51   #9

 
Syc's Avatar
 
elite*gold: 666
Join Date: Apr 2011
Posts: 5,810
Received Thanks: 2,418
How about both of you calm down a bit?

@ you should really describe your problem in detail and maybe even create your own thread. Nobody can help you if you don't explain what you are doing and what exactly is not working.
Syc is offline  
Old 10/11/2017, 16:50   #10
 
Kurisu Makise's Avatar
 
elite*gold: 0
Join Date: Dec 2016
Posts: 22
Received Thanks: 4
Quote:
Originally Posted by Xio. View Post
Fking germans..
Quote:
Originally Posted by Xio. View Post
works for OP. Better go learn how to use google
Quote:
Originally Posted by Xio. View Post
run your app as admin... jesus fucking christ.
Quote:
Originally Posted by Syc View Post
How about both of you calm down a bit?

@ you should really describe your problem in detail and maybe even create your own thread. Nobody can help you if you don't explain what you are doing and what exactly is not working.
I will write a more detailed ticket to the support all right.

But you ignore this insults and racism ?
A moderator has to take action instead of just watching seriously.
Kurisu Makise is offline  
Thanks
1 User
Old 10/11/2017, 17:25   #11
 
killzone's Avatar
 
elite*gold: 100
Join Date: Mar 2006
Posts: 1,826
Received Thanks: 430
Calm your **** down people.
We have give him the solutions, its up to him to figure it out on his own.
I have answered him at M.p.g.h.net already with the same thread and further explained HOW to use my function.
killzone is offline  
Old 10/11/2017, 18:00   #12
 
Kurisu Makise's Avatar
 
elite*gold: 0
Join Date: Dec 2016
Posts: 22
Received Thanks: 4
Quote:
Originally Posted by Xio. View Post
The only insult was "Fkin germans" guess what? I'm german.

This is just typical behavior of germans. Complaining without giving any information that could even help remotely. I'm out. Good luck, not going to reply to you again, you need to grow up.

Look at your behavior before you complain about mine.


^ No information


^ No information, playing on my previous statement with an idiotic adaptation



^ No information, insulting, idiotic claim. If you use windows, this code works - if you don't and you try to copy paste this code, you're plain stupid. There is no way it doesn't work for you. Implement it correctly.

your comment was racist anyway

also I wrote a ticket from the beginning but got no respone so I complained in this thread. guess you just dont have enough brain cells to understand that and try to cover it with insults
Kurisu Makise is offline  
Old 10/12/2017, 23:02   #13
 
cookie69's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 627
Received Thanks: 689
Interesting subject...Well, this game is using SetWindowsHookEx to hook the keyboard inputs and I think they are using this to "protect" the game against non-human inputs.
cookie69 is offline  
Reply


Similar Threads Similar Threads
Send packet function (ASM) in game
03/05/2016 - AutoIt - 8 Replies
I have an ASM code : PUSHAD() MOV_ECX(CALL_PACKET) MOV_EAX(Address) // packet array PUSH_EAX() MOV_EDX(0X0048D330) CALL_EDX() POPAD() RET()
std::function of a function returning an std::function
11/11/2013 - C/C++ - 19 Replies
Nun muss ich nach langer Zeit auch mal wieder einen Thread erstellen, weil mir Google nicht mehr weiterhelfen kann. Ich verzweifle an Folgendem Vorhaben: #include <Windows.h> #include <string> #include <iostream> using namespace std;
Running Function 2 after Function 1 finished
09/15/2013 - AutoIt - 3 Replies
Hey, its me again. Im stuck on a problem since yesterday and as much as i hate to ask for help, i really dont know what else to try. I want Function 2 to run after Function 1 has finished. I tried GuiCtrlSetOnEvent and MsgLoop, but i dont really understand it. I tried to read tutorials but they didnt help at all. The line that are underline is what im talking about. I want gamestart() to run first and when its finished, i want iniviteteam() to run. #AutoIt3Wrapper_UseX64=n...
[VIP-function] ToxicSYS [VIP-function]
08/14/2010 - WarRock Hacks, Bots, Cheats & Exploits - 1 Replies
heeeey E-pvpers :pimp: this is a new hack by TSYS Status : UNDETECTED Functions (VIDEO) : YouTube - WarRock - Bikini event VIP hack
Hshield send function hook
10/11/2008 - Kal Online - 12 Replies
ey kann mir wer nen tipp geben wie man die addressen rauskriegt von int vom hshield für recv und send funktion damit die gehooked wird??



All times are GMT +2. The time now is 21:57.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.