Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › Visual Basic Programming › Send Function key to a game

QuestionSend Function key to a game

Posts 1–9 of 9 · Page 1 of 1
Ell0ll
Ell0ll
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 FVK (OSK) 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 ?

I hope some can do it
#1 · 8y ago
IN
infidel_
Which game you are trying to send the keys to?
There are games that blocks direct input if not from keyboards.
Also, there are classes that will not work on DirectX games.
There are also games the blocks SendInput, SendMessage, PostMessage & VK_Keys.

If you are trying to make a bot, its best you work on OCR & Look for Interceptor.dll.
#2 · 8y ago
Ell0ll
Ell0ll
Quote Originally Posted by infidel_ View Post
Which game you are trying to send the keys to?
There are games that blocks direct input if not from keyboards.
Also, there are classes that will not work on DirectX games.
There are also games the blocks SendInput, SendMessage, PostMessage & VK_Keys.

If you are trying to make a bot, its best you work on OCR & Look for Interceptor.dll.
Link of game

how do i know if it is blocking - direct input if not from keyboards

i think it is not blocking because Windows 7 OSK and FVK that i download it both are working i can send Function keys with it

Windows 7 OSK and FVK >>> which way do you think are using to make it

SendInput or SendMessage or PostMessage or VK_Keys

Can you write an example code for each way of these ( SendInput, SendMessage, PostMessage and VK_Keys )

also what about this ( Interceptor.dll )

Thanks
#3 · edited 8y ago · 8y ago
IN
infidel_
There are ways.
1. Try AutoIt or AutoHotkey
2. Im using https://www.kbdedi*****m/manual/low_level_vk_list.html
3. https://******.com/jasonpang/Interce...ster/README.md

Each of those are different approach but achieves the same thing, automation of Key Sends & Mouse Inputs.

VB.NET
For VK_Keys, you have to declare it as constants.
Code:
#Region "Mouse & Key Events Declaration"
    Declare Function mouse_event Lib "user32.dll" Alias "mouse_event" (ByVal dwFlags As Int32, ByVal dX As Int32, ByVal dY As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) As Boolean

    Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
             (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

    Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
                 (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As IntPtr
    Function MakeDWord(ByVal LoWord As Integer, ByVal HiWord As Integer) As Long
        MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
    End Function
#End Region
Code:
Const WM_KEYDOWN As Integer = &H100
Const WM_KEYUP As Integer = &H101
Const VK_TAB As Integer = &H9 'Sample key (TAB Key)
Calling it like this:
Code:
  Dim GameWin As IntPtr = FindWindow(Nothing, "YourTargetGameWindowName")
    SendMessage(gameWin, WM_KEYDOWN, VK_TAB, 0)
    SendMessage(gameWin, WM_KEYUP, VK_TAB, 0)
FOR AUTOIT
Reference AutoItX64.dll into your project and call it like this:
Import AutoIt Library first
Code:
Imports AutoItX3Lib
Then, declare a variable that links to the AutoItX3Lib
Code:
Dim au3 As New AutoItX3
And Call it like this:
Code:
'ControlSend ( "title", "text", controlID, "string" [, flag = 0] ) '<= The AutoIt Syntax
au3.ControlSend("TargetGameWindowName", "", "", "{2}") '<= The Vb.net AutoIt Syntax
{2} is the Raw Key for #2.
Which means, it sends Keys.2 directly to the game window.
Which means, it works EVEN if the window is hidden or minimized.
#4 · edited 8y ago · 8y ago
Ell0ll
Ell0ll
Quote Originally Posted by infidel_ View Post
There are ways.
1. Try AutoIt or AutoHotkey
2. Im using https://www.kbdedi*****m/manual/low_level_vk_list.html
3. https://******.com/jasonpang/Interce...ster/README.md

Each of those are different approach but achieves the same thing, automation of Key Sends & Mouse Inputs.

VB.NET
For VK_Keys, you have to declare it as constants.
Code:
#Region "Mouse & Key Events Declaration"
    Declare Function mouse_event Lib "user32.dll" Alias "mouse_event" (ByVal dwFlags As Int32, ByVal dX As Int32, ByVal dY As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) As Boolean

    Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
             (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

    Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
                 (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As IntPtr
    Function MakeDWord(ByVal LoWord As Integer, ByVal HiWord As Integer) As Long
        MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
    End Function
#End Region
Code:
Const WM_KEYDOWN As Integer = &H100
Const WM_KEYUP As Integer = &H101
Const VK_TAB As Integer = &H9 'Sample key (TAB Key)
Calling it like this:
Code:
  Dim GameWin As IntPtr = FindWindow(Nothing, "YourTargetGameWindowName")
    SendMessage(gameWin, WM_KEYDOWN, VK_TAB, 0)
    SendMessage(gameWin, WM_KEYUP, VK_TAB, 0)
FOR AUTOIT
Reference AutoItX64.dll into your project and call it like this:
Import AutoIt Library first
Code:
Imports AutoItX3Lib
Then, declare a variable that links to the AutoItX3Lib
Code:
Dim au3 As New AutoItX3
And Call it like this:
Code:
'ControlSend ( "title", "text", controlID, "string" [, flag = 0] ) '<= The AutoIt Syntax
au3.ControlSend("TargetGameWindowName", "", "", "{2}") '<= The Vb.net AutoIt Syntax
{2} is the Raw Key for #2.
Which means, it sends Keys.2 directly to the game window.
Which means, it works EVEN if the window is hidden or minimized.

Firstly Thanks for your reply

Secondly explanation of what i have done

i tried every way you told me about it

AutoIt : Error: A reference could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component
i tried use regsvr32 AutoItX3.dll > so i can add it as reference
i used your code to test it >>> it is working also but letters numbers only it can't send Function keys to the game

AutoHotkey : this time the Error: A reference could not be added > did not appear and i could add it as reference with no problems
but i tried use Import AutoHotkey Library i could not there is nothing so i could not test it

Interceptor : Error: A reference could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component
this time i tried use regsvr32 interception.dll > so i can add it as reference
another error appear >>> the module was loaded but the entry-point dllregisterserver was not found Make sure that "interception.dll" is a valid DLL or ocx file and then try again
i tried again to add it as a reference same error appear so i could not test it too

SendMessage : i tried this way it does not send any thing not even numbers or letters

Code:
  Dim GameWin As IntPtr = FindWindow(Nothing, "YourTargetGameWindowName")
    SendMessage(gameWin, WM_KEYDOWN, VK_TAB, 0)
    SendMessage(gameWin, WM_KEYUP, VK_TAB, 0)
PostMessage : i replaced "SendMessage" with "PostMessage" >>> it can send letters and numbers but not function keys

Code:
  Dim GameWin As IntPtr = FindWindow(Nothing, "YourTargetGameWindowName")
    PostMessage(gameWin, WM_KEYDOWN, VK_TAB, 0)
    PostMessage(gameWin, WM_KEYUP, VK_TAB, 0)
#5 · 8y ago
IN
infidel_
Try sending Function Keys using Autoit without making it a Raw Key.
So just Send("F1") see if that works.

As for PostMessage / SendMessage, like I said, declare the Key first as constant.
Const VK_F1 As Integer = &H70
#6 · 8y ago
MI
MikeRohsoft
for GTA it was enough to do a break, between calling up and down
Code:
  keybd_event(0x57, xKey, 0, 0)
  Sleep(50)
  keybd_event(0x57, xKey, KEYEVENTF_KEYUP, 0)
#7 · 8y ago
IN
infidel_
Its also possible that he is sending the keys to wrong window.
#8 · 8y ago
Ell0ll
Ell0ll
Quote Originally Posted by infidel_ View Post
Try sending Function Keys using Autoit without making it a Raw Key.
So just Send("F1") see if that works.

As for PostMessage / SendMessage, like I said, declare the Key first as constant.
Const VK_F1 As Integer = &H70
Not working

Quote Originally Posted by MikeRohsoft View Post
for GTA it was enough to do a break, between calling up and down
Code:
  keybd_event(0x57, xKey, 0, 0)
  Sleep(50)
  keybd_event(0x57, xKey, KEYEVENTF_KEYUP, 0)
Not working

Quote Originally Posted by infidel_ View Post
Its also possible that he is sending the keys to wrong window.
How ? i am able to send any other keys (A,B,C, etc) but not Function keys

Do not believe me
it is easy
Any one can test it by downloading the game

Link of game
#9 · 8y ago
Posts 1–9 of 9 · Page 1 of 1

Post a Reply

Similar Threads

  • VB6 codes sending Function Keys to my online gamesBy joi in Visual Basic Programming
    6Last post 10y ago
  • Sending Keys in DirectX GameBy WarOfRen in Visual Basic Programming
    4Last post 11y ago
  • Focusing And Sending Keys To Particular GameBy Crostator in Visual Basic Programming
    5Last post 14y ago
  • [HELP]Send random keys?By Pixie in Visual Basic Programming
    26Last post 16y ago
  • [Sell] PC CD Keys for NEWEST GamesBy Tolumbar in Trade Accounts/Keys/Items
    45Last post 17y ago

Tags for this Thread

#function key#game#vb2010