Jump to content
  • Advertisement

Dr. David Bowman

Member
  • Content Count

    14
  • Joined

  • Last visited

Community Reputation

1 Neutral

About Dr. David Bowman

  • Rank
    Member

Personal Information

  • Role
    Programmer
  • Interests
    Art
    Audio
    Design
    DevOps
    Education
    Production
    Programming
    QA

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. A very good day to you All, I hope you are doing Very Well, Please kindly see the attached code for a C# Program This C# Program will Load an External EXE Program into Memory This C# Program will then do a Function Call to Run that EXE Program that sits in Memory The External EXE Program is an Executable that sending Keypress to the Desktop It does nothing except sending out keypresses to the Desktop The Calling Function to Run the EXE From Memory is listed below //Execute the assembly exeAssembly.EntryPoint.Invoke(null, null); //no parameters Is there any way for me to call the above function as many times as I want so that I can keep on running the EXE from memory as many times as I want ? The below code works for the 1st call to run the EXE On the second call to run the EXE - The code returns an error message and is not able to proceed any further What I would like to be able to do is to 1) Load the EXE into Memory 2) Set it up in such a way where I can Call the Invoke Function as many times as I wish in order to Run the External Keypress Program as many times as I wish Is there any way to do this ? Secondly I would like for the external EXE program to be able to interact with all the surrounding applications that are running on the Windows Desktop This is because the external EXE program is actually a program that sends out keypresses I am calling and running this external EXE program multiple times in order to deliver multiple keypresses many many times over The keypresses are to interact with any Running APP that I have opened in the Windows desktop And thus I would like for this keypresses app to be able to affect and interact with all the apps on the Windows desktop How can I modify the code so that I can allow for this external EXE to be able to interact with all running desktop apps? Here is the code using System; using System.Collections.Generic; using System.Windows.Forms; //Needed using System.Reflection; using System.IO; namespace MemoryLauncher { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { RunInternalExe("x.exe"); } private static void RunInternalExe(string exeName) { //Get the current assembly Assembly assembly = Assembly.GetExecutingAssembly(); //Get the assembly's root name string rootName = assembly.GetName().Name; //Get the resource stream Stream resourceStream = assembly.GetManifestResourceStream(rootName + "." + exeName); //Verify the internal exe exists if (resourceStream == null) return; //Read the raw bytes of the resource byte[] resourcesBuffer = new byte[resourceStream.Length]; resourceStream.Read(resourcesBuffer, 0, resourcesBuffer.Length); resourceStream.Close(); //Load the bytes as an assembly Assembly exeAssembly = Assembly.Load(resourcesBuffer); //Execute the assembly exeAssembly.EntryPoint.Invoke(null, null); //no parameters } } }
  2. Dear Sir, Thank you very much for your interest in my Thread and also for the kind advice I have managed to combined everything into 1 .CS File as shown below I have managed to get the whole code down to only 1 Compile Error Message There are no Warning Messages too The 1 Error Message is this Error Message - Error CS5001 Program does not contain a static 'Main' method suitable for an entry point WindowsFormsApp3 Can someone please kindly help me out on this Hope to hear from you soon Thank you very much for your time and kind help Kind Regards as Always Sir //Error Message - Error CS5001 Program does not contain a static 'Main' method suitable for an entry point WindowsFormsApp3 using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Text; using System.Diagnostics; public class Program { bool lctrlKeyPressed; bool f1KeyPressed; [STAThread] public void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); LowLevelKeyboardHook kbh = new LowLevelKeyboardHook(); kbh.OnKeyPressed += kbh_OnKeyPressed; kbh.OnKeyUnpressed += kbh_OnKeyUnPressed; kbh.HookKeyboard(); Application.Run(); kbh.UnHookKeyboard(); } void kbh_OnKeyPressed(object sender, Keys e) { if (e == Keys.LControlKey) { lctrlKeyPressed = true; } else if (e == Keys.F1) { f1KeyPressed = true; } CheckKeyCombo(); } void kbh_OnKeyUnPressed(object sender, Keys e) { if (e == Keys.LControlKey) { lctrlKeyPressed = false; } else if (e == Keys.F1) { f1KeyPressed = false; } } void CheckKeyCombo() { if (lctrlKeyPressed && f1KeyPressed) { //Open Form } } } public class LowLevelKeyboardHook { private const int WH_KEYBOARD_LL = 13; private const int WM_KEYDOWN = 0x0100; private const int WM_SYSKEYDOWN = 0x0104; private const int WM_KEYUP = 0x101; private const int WM_SYSKEYUP = 0x105; [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool UnhookWindowsHookEx(IntPtr hhk); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr GetModuleHandle(string lpModuleName); public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam); public event EventHandler<Keys> OnKeyPressed; public event EventHandler<Keys> OnKeyUnpressed; private LowLevelKeyboardProc _proc; private IntPtr _hookID = IntPtr.Zero; public LowLevelKeyboardHook() { _proc = HookCallback; } public void HookKeyboard() { _hookID = SetHook(_proc); } public void UnHookKeyboard() { UnhookWindowsHookEx(_hookID); } private IntPtr SetHook(LowLevelKeyboardProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0); } } private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN) { int vkCode = Marshal.ReadInt32(lParam); OnKeyPressed.Invoke(this, ((Keys)vkCode)); } else if (nCode >= 0 && wParam == (IntPtr)WM_KEYUP || wParam == (IntPtr)WM_SYSKEYUP) { int vkCode = Marshal.ReadInt32(lParam); OnKeyUnpressed.Invoke(this, ((Keys)vkCode)); } return CallNextHookEx(_hookID, nCode, wParam, lParam); } }
  3. Dear Sir, Thank you for coming back to this Thread and taking a look at my Code I really appreciate it very much I have done my best and please kindly see the code below for what I have combined so far The code does not work for some reason - The Error Message is - Line 14 - The name "kbh_OnKeyPressed" does not exist in the current context Line 15 - The name "Kbh_OnKeyUnpressed" does not exist in the current context May I please kindly ask how can I resolve this issue Hope to hear from you soon - Thank you and kind regards as always Sir using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Windows.Forms; public class Program { public static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); LowLevelKeyboardHook kbh = new LowLevelKeyboardHook(); kbh.OnKeyPressed += kbh_OnKeyPressed; kbh.OnKeyUnpressed += kbh_OnKeyUnpressed; kbh.HookKeyboard(); Application.Run(); kbh.UnHookKeyboard(); } } public class LowLevelKeyboardHook { private const int WH_KEYBOARD_LL = 13; private const int WM_KEYDOWN = 0x0100; private const int WM_SYSKEYDOWN = 0x0104; private const int WM_KEYUP = 0x101; private const int WM_SYSKEYUP = 0x105; [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool UnhookWindowsHookEx(IntPtr hhk); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr GetModuleHandle(string lpModuleName); public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam); public event EventHandler<Keys> OnKeyPressed; public event EventHandler<Keys> OnKeyUnpressed; private LowLevelKeyboardProc _proc; private IntPtr _hookID = IntPtr.Zero; public LowLevelKeyboardHook() { _proc = HookCallback; } public void HookKeyboard() { _hookID = SetHook(_proc); } public void UnHookKeyboard() { UnhookWindowsHookEx(_hookID); } private IntPtr SetHook(LowLevelKeyboardProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0); } } private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN) { int vkCode = Marshal.ReadInt32(lParam); OnKeyPressed.Invoke(this, ((Keys)vkCode)); } else if(nCode >= 0 && wParam == (IntPtr)WM_KEYUP ||wParam == (IntPtr)WM_SYSKEYUP) { int vkCode = Marshal.ReadInt32(lParam); OnKeyUnpressed.Invoke(this, ((Keys)vkCode)); } return CallNextHookEx(_hookID, nCode, wParam, lParam); } }
  4. May I please kindly ask I need to merge all my .CS Files into 1 big .CS Main File in order for everything to work I have the following code which I found on the Internet I guess that this First Section of Code is for the .CS File - LowLevelKeyboardHook.CS using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Windows.Forms; public class LowLevelKeyboardHook { private const int WH_KEYBOARD_LL = 13; private const int WM_KEYDOWN = 0x0100; private const int WM_SYSKEYDOWN = 0x0104; private const int WM_KEYUP = 0x101; private const int WM_SYSKEYUP = 0x105; [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool UnhookWindowsHookEx(IntPtr hhk); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr GetModuleHandle(string lpModuleName); public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam); public event EventHandler<Keys> OnKeyPressed; public event EventHandler<Keys> OnKeyUnpressed; private LowLevelKeyboardProc _proc; private IntPtr _hookID = IntPtr.Zero; public LowLevelKeyboardHook() { _proc = HookCallback; } public void HookKeyboard() { _hookID = SetHook(_proc); } public void UnHookKeyboard() { UnhookWindowsHookEx(_hookID); } private IntPtr SetHook(LowLevelKeyboardProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0); } } private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN) { int vkCode = Marshal.ReadInt32(lParam); OnKeyPressed.Invoke(this, ((Keys)vkCode)); } else if(nCode >= 0 && wParam == (IntPtr)WM_KEYUP ||wParam == (IntPtr)WM_SYSKEYUP) { int vkCode = Marshal.ReadInt32(lParam); OnKeyUnpressed.Invoke(this, ((Keys)vkCode)); } return CallNextHookEx(_hookID, nCode, wParam, lParam); } } Now these Code are for the Main.CS File kbh = new LowLevelKeyboardHook(); kbh.OnKeyPressed += kbh_OnKeyPressed; kbh.OnKeyUnpressed += kbh_OnKeyUnpressed; kbh.HookKeyboard(); I suspect the following Code could be found in the HookCallBack in the - LowLevelKeyboardHook.CS File bool lctrlKeyPressed; bool f1KeyPressed; void kbh_OnKeyPressed(object sender, Keys e) { if (e == Keys.LControlKey) { lctrlKeyPressed = true; } else if (e == Keys.F1) { f1KeyPressed= true; } CheckKeyCombo(); } void kbh_OnKeyUnPressed(object sender, Keys e) { if (e == Keys.LControlKey) { lctrlKeyPressed = false; } else if (e == Keys.F1) { f1KeyPressed= false; } } void CheckKeyCombo() { if (lctrlKeyPressed && f1KeyPressed) { //Open Form } } And Finally Here is the Code for the Main.CS File [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); LowLevelKeyboardHook kbh = new LowLevelKeyboardHook(); kbh.OnKeyPressed += kbh_OnKeyPressed; kbh.OnKeyUnpressed += kbh_OnKeyUnpressed; kbh.HookKeyboard(); Application.Run(); kbh.UnHookKeyboard(); } What I would like to know is - How can I combine all These Codes into 1 Main Big .CS File ? E.G. How do I combine everything in the File - LowLevelKeyboardHook.CS into the Main.CS File ? Hope to hear from you soon Thank you very much for your time and kind help Kind Regards as Always Sir
  5. Thank you extremely much for all your time and kind help I really appreciate it very much I hope you have a great week ahead Sir Kind Regards as Always
  6. On that matter I was wondering if any kind soul knows of a Game Macro Engine that can be bound to more then 1 Key Hope to hear from you soon Thank you and kind regards
  7. Thank you everyone for replying to my Newbie's questions The reason I need this is because I am using the Jitbit Macro Recorder I am not able to get the Jitbit Macro Recorder to use 3 Keyboard Keys for the Trigger macro E.G. I use these 3 Keys - Down Arrow + Left Arrow + A But the Jitbit Macro Recorder does have a small C# Functionality It is able to handle simple C# programs from within the Macro Engine And the Jitbit Macro C# Engine must use these C# Procedure calls public class Program { public static void Main() { } } I am not sure how I can get the Jitbit Macro Engine to accept the Binding of 3 Keys for the Macro Thank you and kind regards
  8. A very good day to you Sir, I hope you are doing Great Sir, I am trying to get the C# GetKeyPress Function to work Please kindly see my C# Code attached Can someone please kindly help me out Thank you very much for your time and kind help Kind Regards as Always using System; public class Program { public static void Main() { KeyEventArgs GetKeys; if (GetKeys.KeyCode == Keys.Enter) { System.Windows.Forms.MessageBox.Show("Enter Key Pressed"); } } }
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!