Mouse Button > keystroke
-
Hey, I'd like to develop some open source software for the public mainly for gaming. I would like to take mouse input and convert it so that the computer will assume it as a keystoke. For example on an intellimouse which has 5buttons if the middle mouse button is pressed i would like to fire say a Keystroke p. The old microsoft software allowed you to do this, the new ones do not, and hence here i am Atul :eek::eek::eek:
-
Hey, I'd like to develop some open source software for the public mainly for gaming. I would like to take mouse input and convert it so that the computer will assume it as a keystoke. For example on an intellimouse which has 5buttons if the middle mouse button is pressed i would like to fire say a Keystroke p. The old microsoft software allowed you to do this, the new ones do not, and hence here i am Atul :eek::eek::eek:
Do a search on hooks (intercepting the mouse input at a system wide low level) and the SendInput call (simulating a keyboard press). Both of these things are low level and not represented in the framwork classes, so you'll have to do some interop to get this stuff done in C#.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins -
Hey, I'd like to develop some open source software for the public mainly for gaming. I would like to take mouse input and convert it so that the computer will assume it as a keystoke. For example on an intellimouse which has 5buttons if the middle mouse button is pressed i would like to fire say a Keystroke p. The old microsoft software allowed you to do this, the new ones do not, and hence here i am Atul :eek::eek::eek:
Good Luck! :-D Perl combines all the worst aspects of C and Lisp: a billion different sublanguages in one monolithic executable. It combines the power of C with the readability of PostScript. -- Jamie Zawinski
-
Hey, I'd like to develop some open source software for the public mainly for gaming. I would like to take mouse input and convert it so that the computer will assume it as a keystoke. For example on an intellimouse which has 5buttons if the middle mouse button is pressed i would like to fire say a Keystroke p. The old microsoft software allowed you to do this, the new ones do not, and hence here i am Atul :eek::eek::eek:
Update: part of the solution[^] the answer was under my nose :-O:-O:-O this is part of the solution just need to stick a gui on and work out how to fire a keyboard event and i'm nearly there :) Hopefully all gamers can use this who have 5 button mice and no software ;P once i'm finished i'll stick the source up on here
-
Update: part of the solution[^] the answer was under my nose :-O:-O:-O this is part of the solution just need to stick a gui on and work out how to fire a keyboard event and i'm nearly there :) Hopefully all gamers can use this who have 5 button mice and no software ;P once i'm finished i'll stick the source up on here
SendInput is the Win32 function you want to use for this. It can be used to simulate keyboard and mouse actually. You'll definitely need to use interop to make the calls from C#. I've played around with using it to simulate mouse calls, and it's worked fine in other DirectX games (at the time I was trying to do a little macroing in a popular MMORPG). If you run into any problems, let me know.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins -
SendInput is the Win32 function you want to use for this. It can be used to simulate keyboard and mouse actually. You'll definitely need to use interop to make the calls from C#. I've played around with using it to simulate mouse calls, and it's worked fine in other DirectX games (at the time I was trying to do a little macroing in a popular MMORPG). If you run into any problems, let me know.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbinsas.thakor@ntlworld.com could i speak to you by email direct ? it would be greatly appreciated Thanks Atul
-
as.thakor@ntlworld.com could i speak to you by email direct ? it would be greatly appreciated Thanks Atul
Here's a chunk of code I wrote. This class was basically being hosted by remoting (thus the MarshalByRefObject), but it moves the mouse where you want it. It shows how to interop with SendInput (importing the definition and defining a few structures you'll need).
using System;
using System.Runtime.InteropServices;[StructLayout(LayoutKind.Explicit, Size=28)]
public struct Input
{
[FieldOffset (0)]
public uint type;
[FieldOffset (4)]
public MouseInput mi;
[FieldOffset (4)]
public KeyboardInput ki;
[FieldOffset (4)]
public HardwareInput hi;public const uint INPUT_MOUSE = 0;
public const uint INPUT_KEYBOARD = 1;
public const uint INPUT_HARDWARE = 2;
}[StructLayout(LayoutKind.Sequential, Size=24)]
public struct MouseInput
{
public int dx;
public int dy;
public uint mouseData;
public uint -
Here's a chunk of code I wrote. This class was basically being hosted by remoting (thus the MarshalByRefObject), but it moves the mouse where you want it. It shows how to interop with SendInput (importing the definition and defining a few structures you'll need).
using System;
using System.Runtime.InteropServices;[StructLayout(LayoutKind.Explicit, Size=28)]
public struct Input
{
[FieldOffset (0)]
public uint type;
[FieldOffset (4)]
public MouseInput mi;
[FieldOffset (4)]
public KeyboardInput ki;
[FieldOffset (4)]
public HardwareInput hi;public const uint INPUT_MOUSE = 0;
public const uint INPUT_KEYBOARD = 1;
public const uint INPUT_HARDWARE = 2;
}[StructLayout(LayoutKind.Sequential, Size=24)]
public struct MouseInput
{
public int dx;
public int dy;
public uint mouseData;
public uint -
Here's a chunk of code I wrote. This class was basically being hosted by remoting (thus the MarshalByRefObject), but it moves the mouse where you want it. It shows how to interop with SendInput (importing the definition and defining a few structures you'll need).
using System;
using System.Runtime.InteropServices;[StructLayout(LayoutKind.Explicit, Size=28)]
public struct Input
{
[FieldOffset (0)]
public uint type;
[FieldOffset (4)]
public MouseInput mi;
[FieldOffset (4)]
public KeyboardInput ki;
[FieldOffset (4)]
public HardwareInput hi;public const uint INPUT_MOUSE = 0;
public const uint INPUT_KEYBOARD = 1;
public const uint INPUT_HARDWARE = 2;
}[StructLayout(LayoutKind.Sequential, Size=24)]
public struct MouseInput
{
public int dx;
public int dy;
public uint mouseData;
public uintI have just started playing with the code and read that its possible to make a global hook :( http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q319524 :(
-
I have just started playing with the code and read that its possible to make a global hook :( http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q319524 :(
I was wondering how that was going to work (I'm actually not sure the exact purpose of installing a hook that's not global to be honest...I need to read more about that). I knew you had to write a DLL with a specific signature that gets loaded by every application (I wrote one once for a kiosk that disabled and enabled things like CTRL-ALT-DELETE once they typed in a password). I looks like almost the entire project would have to be a straight Win32 DLL in C/C++ (since the keyboard hook would be calling SendInput). You'd most likely write an application that installs and uninstalls the hook as well (which wouldn't necessarily have to be written in C/C++). Have you ever done any C++? This DLL wouldn't actually be that big...you just have to get it perfect since everything is calling it ;). If I get a chance tonight, I'll play around with writing a hook (busy at work at the moment).
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins -
I was wondering how that was going to work (I'm actually not sure the exact purpose of installing a hook that's not global to be honest...I need to read more about that). I knew you had to write a DLL with a specific signature that gets loaded by every application (I wrote one once for a kiosk that disabled and enabled things like CTRL-ALT-DELETE once they typed in a password). I looks like almost the entire project would have to be a straight Win32 DLL in C/C++ (since the keyboard hook would be calling SendInput). You'd most likely write an application that installs and uninstalls the hook as well (which wouldn't necessarily have to be written in C/C++). Have you ever done any C++? This DLL wouldn't actually be that big...you just have to get it perfect since everything is calling it ;). If I get a chance tonight, I'll play around with writing a hook (busy at work at the moment).
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbinsi got hold of a dll hook someone used in VB maybe its convertable to be used in .net ? http://www.allapi.net/php/redirect/redirect.php?action=download&id=372 thats the link to the sample prog and .dll nope i havent much experience in c++ only the very basics of c but i am willing to learn :)
-
I was wondering how that was going to work (I'm actually not sure the exact purpose of installing a hook that's not global to be honest...I need to read more about that). I knew you had to write a DLL with a specific signature that gets loaded by every application (I wrote one once for a kiosk that disabled and enabled things like CTRL-ALT-DELETE once they typed in a password). I looks like almost the entire project would have to be a straight Win32 DLL in C/C++ (since the keyboard hook would be calling SendInput). You'd most likely write an application that installs and uninstalls the hook as well (which wouldn't necessarily have to be written in C/C++). Have you ever done any C++? This DLL wouldn't actually be that big...you just have to get it perfect since everything is calling it ;). If I get a chance tonight, I'll play around with writing a hook (busy at work at the moment).
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbinshttp://msdn.microsoft.com/msdnmag/issues/02/10/cuttingedge/default.aspx Apparently a Global hook....... doesnt seem to do much though :-O:-O:-O
-
i got hold of a dll hook someone used in VB maybe its convertable to be used in .net ? http://www.allapi.net/php/redirect/redirect.php?action=download&id=372 thats the link to the sample prog and .dll nope i havent much experience in c++ only the very basics of c but i am willing to learn :)
That app uses Visual Basic (not VB.NET) to create a DLL. His DLL might have even been written in C/C++, but in any event you can specify exactly how the DLL should look in any of those languages (some more easier than others) I could be wrong (wouldn't be the first time), but I don't think you can create a .NET "Win32 Dll" (there might be some third party stuff that lets you do this, but I don't know). That is to say, I don't think you can create something in .NET that's just a DLL (and not a managed assembly). You can create a DLL that exposes COM functionality, but I don't think you can get as specific as you need for this DLL in .NET (either VB.NET or C#). I think this job would actually require something other than .NET.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins -
I was wondering how that was going to work (I'm actually not sure the exact purpose of installing a hook that's not global to be honest...I need to read more about that). I knew you had to write a DLL with a specific signature that gets loaded by every application (I wrote one once for a kiosk that disabled and enabled things like CTRL-ALT-DELETE once they typed in a password). I looks like almost the entire project would have to be a straight Win32 DLL in C/C++ (since the keyboard hook would be calling SendInput). You'd most likely write an application that installs and uninstalls the hook as well (which wouldn't necessarily have to be written in C/C++). Have you ever done any C++? This DLL wouldn't actually be that big...you just have to get it perfect since everything is calling it ;). If I get a chance tonight, I'll play around with writing a hook (busy at work at the moment).
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. HubbinsGoogle 2 Win it seems http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=872&lngWId=10 has the source code for someone who has created something pretty much what i want in vb.net just gotta translate ye old code to c# now or just use the vb.net stuff if your still intrested in having a mess about with this project your very welcome :) as your input has been extremely value!
-
Google 2 Win it seems http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=872&lngWId=10 has the source code for someone who has created something pretty much what i want in vb.net just gotta translate ye old code to c# now or just use the vb.net stuff if your still intrested in having a mess about with this project your very welcome :) as your input has been extremely value!
k had a look at the source........
Private Declare Function GetCursor Lib "user32" () As Int32 Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (ByRef lpPoint As POINTAPI) As Int32 Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Int32, ByVal yPoint As Int32) As Int32 Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Int32, ByRef lpdwProcessId As Int32) As Int32 Private Declare Function AttachThreadInput Lib "user32" Alias "AttachThreadInput" (ByVal idAttach As Int32, ByVal idAttachTo As Int32, ByVal fAttach As Int32) As Int32 Private Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Int32) As Int16
k i understand GetCursor is the function name and it returns in Integer ....... but "user32" refers to a library and i have no idea how to port that part of the code over to c# :-O just out of interest is this...... code actually intercepting the events or simply reading them as they fly by as i need to read process and act -
Google 2 Win it seems http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=872&lngWId=10 has the source code for someone who has created something pretty much what i want in vb.net just gotta translate ye old code to c# now or just use the vb.net stuff if your still intrested in having a mess about with this project your very welcome :) as your input has been extremely value!
Not sure if that technique would work for DirectX games etc. It might not be low level enough. I think hooks might be the only way to do it, and doing global hooks seems truly impossible to do entirely in .NET. It's not too hard to get unmanaged code (C/C++/VB) to talk to managed code via a COM. That might be the easiest way: create a C/C++ hook, create a .NET class that gets wrapped as a COM component, let the hook call the .NET class. This would allow you to do most of your development in C#, but I think some C/C++ is going to be unavoidable.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins -
Not sure if that technique would work for DirectX games etc. It might not be low level enough. I think hooks might be the only way to do it, and doing global hooks seems truly impossible to do entirely in .NET. It's not too hard to get unmanaged code (C/C++/VB) to talk to managed code via a COM. That might be the easiest way: create a C/C++ hook, create a .NET class that gets wrapped as a COM component, let the hook call the .NET class. This would allow you to do most of your development in C#, but I think some C/C++ is going to be unavoidable.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbinshttp://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1052&lngWId=10 This one is definately low level enough :D seems it anyway
Public Class frmMain Inherits System.Windows.Forms.Form Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As LowLevelKeyboardProcDelegate, ByVal hMod As Integer, ByVal dwThreadId As Integer) As Integer Declare Function UnhookWindowsHookEx Lib "user32" Alias "UnhookWindowsHookEx" (ByVal hHook As Integer) As Integer Delegate Function LowLevelKeyboardProcDelegate(ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer Declare Function CallNextHookEx Lib "user32" Alias "CallNextHookEx" (ByVal hHook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer Const WH_KEYBOARD_LL = 13 Structure KBDLLHOOKSTRUCT Dim vkCode As Integer Dim scanCode As Integer Dim flags As Integer Dim time As Integer Dim dwExtraInfo As Integer End Structure Dim intLLKey As Integer #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Private Sub InitializeComponent() Me.lblInfo = New System.Windows.Forms.Label() Me.SuspendLayout() ' 'lblInfo ' Me.lblInfo.Location = New System.Drawing.Point(16, 16) Me.lblInfo.Name = "lblInfo" Me.lblInfo.Size = New System.Drawing.Size(216, 88) Me.lblInfo.TabIndex = 0 Me.lblInfo.Text = "Alt-Tab, Alt-Esc, Ctrl-Esc, and the Windows key are disabled. C