|
Hi,
I've been working on an application that captures keystrokes and mouse clicks, which are stored to be played back. To use the playback I am using the SendInput function from the windows api. However my code and builds and runs without any errors yet does not work.
Here is my code at present
StructInput.type = INPUT_MOUSE;
switch (mouseInfo.mButton)
{
case "Left":
StructInput.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
break;
case "Right":
StructInput.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
break;
}
StructInput.mi.dx = mouseInfo.mX;
StructInput.mi.dy = mouseInfo.mY;
StructInput.mi.time = 0;
StructInput.mi.mouseData = 0;
StructInput.mi.dwExtraInfo = GetMessageExtraInfo();
intReturn = SendInput(1, ref StructInput, Marshal.SizeOf(StructInput));
Any advice or help anyone can give me would be much appreciated.
Thanks
|
|
|
|
|
Hi,
More and better information might lead to better help.
you failed to explain what you mean by "does not work"
you have shown only half of the relevant code; in particular the definition of StructInput is rather critical.
and you may have overlooked the fact that, most of the time, dx and dy are relative (hence the d).
Hint: when I need a sequence of points and clicks, I tend to include a delay after each of them, and set it rather large (say 2 sec) while debugging, so I can actually watch it all happen.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi,
thanks for the reply. When I i state it doesn't work I mean the code executes but no keystrokes or mouse clicks are synthesised/played back and no Win32 error is reported back as well hence my confusion.
the definition of StructInput is that it is a variable of the type INPUT which is the struct shown below. I also provided my definiton of the MOUSEINPUT struct
[StructLayout(LayoutKind.Sequential)]
struct MOUSEINPUT
{
public int dx;
public int dy;
public uint mouseData;
public uint dwFlags;
public uint time;
public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Explicit)]
struct INPUT
{
[FieldOffset(0)]
public int type;
[FieldOffset(4)]
public MOUSEINPUT mi;
[FieldOffset(4)]
public KEYBDINPUT ki;
}
I wasn't aware that the x and y co-ordinates of the mouse MOUSEINPUT struct were relative to the application i wanted to synthesize the inputs which may be where im going wrong.
[i tried this but made no difference]
again thanks for the reply
modified on Friday, March 20, 2009 8:07 AM
|
|
|
|
|
Hello,
We are using file based encryption to encrypt programs that have shortcuts on the desktop. Since these files are encrypted, the icons do not load.
After loading the necessary certificates, a simple "F5 refresh" is performed (programmatically) on the desktop window; however, the icons for these previously encrypted programs do not appear.
I'd like to implement relatively the same thing as Tweak UI's Rebuild Icons, but I can not figure out what it is doing.
I have used Winspecter and watched the messages for the progman window. The following strike me as relevant, but I can't find any information on specifics:
WM_USER + 3152 (0x00001050)<br />
WM_USER + 3212 (0x0000108c)<br />
I've also used sysinternals Process Monitor to watch file and registry access, and tweakui.exe only appears to be changing the icon size.
Last, I used sysinternals Process Explorer to watch the call stack, which revealed nothing of much use.
Is anyone familiar with what Tweak UI's Rebuild icons is doing? I've also tried calling WM_CLOSE on the program manager window, and WM_DESTROY; neither of which have any effect on the icons.
Any input is appreciated.
Thanks,
Matt Brown
|
|
|
|
|
Hi,
Try using the shell api to force the refresh. I can't actually verify the code as my desktop icons are just fine and dandy at the moment, but in a strictly non-rigorous test it makes them flash!
Download the missing interop signatures for shell32 from http://www.pinvoke.net/index.aspx[^]
[DllImport("shell32.dll")]
static extern void SHChangeNotify(HChangeNotifyEventID wEventId,
HChangeNotifyFlags uFlags,
IntPtr dwItem1,
IntPtr dwItem2);
static void Main(string[] args) {
SHChangeNotify(HChangeNotifyEventID.SHCNE_ASSOCCHANGED,
HChangeNotifyFlags.SHCNF_IDLIST,
IntPtr.Zero, IntPtr.Zero);
}
Alan.
|
|
|
|
|
|
|
Hello Alan,
After testing, it appears that this the notification that an f5 refresh causes? Is this correct?
Regardless, it doesn't seem to cause solve the problem... maybe TweakUI also clears the icon cache registry value. I'll look into this.
If you have any other ideas on how to cause a refresh, it'd be appreciated.
Thanks!
Matt
|
|
|
|
|
Take a look at:
KB132668: Icons randomly change to different icons[^]
dealing with the shell icon cache[^].
The KB article explains that you can change color depth to rebuild the shell icon cache. The second link is interesting as it explains an way to interact with the icon cache. By the way, this is the solution:
Observing registry access of tweakui.exe revealed access to a registry values:
HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\ reg_sz: Shell Icon Size
First Rebuild Icon Cache reads the Shell Icon Size value, then writes a value of 4, then must run the shell32.dll function SendMessageTimeout, then write the original value to Shell Icon Size.
Here is more information from dealing with the shell icon cache[^]:
You can force a full cache flush by manually changing the the icon size yourself to something
one pixel smaller, broadcasting WM_SETTINGCHANGE and then setting the icon size back to normal again
(obviously followed by another WM_SETTINGCHANGE). The message broadcast is typically done something
like this:
SendMessageTimeout(
HWND_BROADCAST,
WM_SETTINGCHANGE,
SPI_SETNONCLIENTMETRICS,
(LPARAM)"WindowMetrics",
SMTO_NORMAL|SMTO_ABORTIFHUNG,
10000, NULL);
You alter the icon size by manually changing its value in the registry. The key to look at is:
HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics
The values for the icon size are Shell Icon Size and Shell Small Icon Size (both are stored as
strings - not DWORDs). You only need to change one of them to cause the refresh to happen (typically
the large icon size). If those values don't exist, the shell uses the SM_CXICON metric
(GetSystemMetrics) as the default size for large icons, and half of that for the small icon size. If
you're trying to cause a refresh and the registry entry doesn't exist, you can just assume that the
size is set to SM_CXICON.
There you go! Now to test and "problem" solved!
Thanks for your direction Alan!
Matt Brown
source: http://www.programmingforums.org/post87847-9.html[^]
static void RefreshIconCache()
{
RegistryKey k = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("Desktop").OpenSubKey("WindowMetrics", true);
Object OriginalIconSize = k.GetValue("Shell Icon Size");
k.SetValue("Shell Icon Size", (Convert.ToInt32(OriginalIconSize) + 1).ToString());
k.Flush(); k.Close();
int res = 0;
SendMessageTimeout(0xffff, 0x001A, 0, "", 0x0002, 5000, out res);
k = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("Desktop").OpenSubKey("WindowMetrics", true);
k.SetValue("Shell Icon Size", OriginalIconSize);
k.Flush(); k.Close();
SendMessageTimeout(0xffff, 0x001A, 0, "", 0x0002, 5000, out res);
}
modified on Thursday, March 26, 2009 9:15 AM
|
|
|
|
|
Hi there and thanks for reading.
I am currently writing a basic virus scanner but i have hit a problem. I know that a virus will have a signature (a unique order of binary 0's and 1's) that represents how the virus is written. The exact same piece of code will always have the same binary signature.
However, how can i convert a file into its binary format ready to be scanned?
My current idea is to keep virus signatures in an xml file, then scan files in a folder for the signatures stored in the xml file.
I am trung to keep it as simple as possible as i have been asked for a basic virus scanner.
This project is still in its early stages so i may be approaching this completly wrong, if so, pointers would be appreciated.
Regards,
|
|
|
|
|
File.ReadAllBytes will read the file as a byte array.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Then just add foreach in signatures, byte[].Contains, and MessageBox.Show. I *knew* those guys at norton were overcharging!
|
|
|
|
|
I am having a little issue on a project I've been working on for a while.
So I open my project now, then if I try to add a Dataset to it, it throws this error:
(To a windows form)
Failed to create component 'DataSet'. The error message follows:
'Microsoft.VSDesigner.Common.NoCurrentProjectException: Could not retrieve the current project.
at Microsoft.VSDesigner.Common.ProjectItemUtil.GetCurrentProject(Boolean throwException)
and it has a ton more.
But the thing is my project opens just fine. So how come Visual Studio is doing this?
|
|
|
|
|
|
Well I did try doing a repair on the application and that didn't work. I also tried another project and it did the same thing so my project wasn't the one corrupt (YAY!).
I completely uninstalled everything VS2008 related (including SQL and AJAX). I reinstalled the application then my computer crashed! I was working on it remotely so I have to wait till I get back to the office to turn on my computer . This would be a great time for having that vPro technology.
Its strange though because it wasn't a corrupt install (I don't think anyways). I have been using it for 6 months and it just did that today. But if I logged in as someone else it worked. Something got corrupt with my profile, but it took me reinstalling everything and my computer crashing to realize that "Hey, maybe since it worked logging in as someone else, its a profile issue and not the application.". But oh well.
Thanks
|
|
|
|
|
hi people, a few days ago i asked how could i call a form to interact with the desktop from my windows service, because everytime i started the service my form would show but it would show on this blue screen not on my desktop
well Wes and Vikram told advised me not to do this and they mentioned this:
"Do something else. Services should not interact with the desktop. If you really want to do something like this, you have to have another application that communicates with the service. "
but honestly i dont know what they were talking about with this, how can i make an application like this??
can anyone help me with this?, maybe some links or suggestions?
thanks a lot in advance
|
|
|
|
|
There are several ways for IPC
1. Pipes
2. .Net Remoting or WCF
|
|
|
|
|
mirko86 wrote: but honestly i dont know what they were talking about with this
Ok then there are two things you should choose from.
1) Take on work that you do know how to do.
2) Study a subject you don't understand until you do understand.
Note: Study a subject DOES NOT mean ask people in internet forums to explain it to you.
|
|
|
|
|
i just asked for help on where to start, see the first response? now i have a starting point thanks to him ,you didnt help at all
you really dont have to answer you know if some messages annoy you just ignore them man
thanks for the responses people
|
|
|
|
|
You think this is a forum for helping people? well... sometimes yeah, but people mainly just like to moan. Think of it as an 'outlet for stress' forum, you will get alot more out of it that way
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
haha luckily for me people have always been nice and helpful to me except for that guy, he even bothered to come back just to insult me
|
|
|
|
|
|
Hi...
Even though its not a good idea to work with, You can still do it....
write a windows service with an IPC server channel (possibly windows service as a server), create a shared object (Class library) and create an IPC client channel in your application to communicate with the service through your shared object...
In simple .Net Remoting.......
If you have further queries let me know....
Have a Happy Coding.....
|
|
|
|
|
Hello,
I write apllication(.NET 3.5 C#, SQL Server 2k8) (type ERP) with modules like: HRM, SCM, FRM, MRP.
It is multi user application.
I decide store all important data from DB in Dictionaries or List<t> ex. for INVOICE i create Dictionary<int,> etc.
To reduce connection with data base I have mechanism base on events to update specific data in my Dictionaries.
I chose this solution because I don't want once again fill my GridView from DataBase when one record has been changed by another user.
To synchronize my Dictionaries I want to use Query Notification and tracking changes mechanism (SQL Server 2008).
And all work fine but ....
Hypothetical situation.
I have for example 20 Dictionaries and any of this Dictionary have 2000-5000 elements.I fill it when the user logs on to an application.
How does it affect the weight of memory?
Is that way - casched Dictionaries - is a better solution then load all data (ex.Invoices) from data base when i need use it ?
Sorry for my English. It is not perfect.
|
|
|
|
|
Such extensive caching is usually not required unless you have some tremendous load on your servers. Generally speaking, you should avoid caching as muc has possible because it adds an additional level of complexity that must be managed in addition to managing the data in the database. You greatly increase the risk of data corruption but caching everything all the time, because it is now your responsibility to make absolutely certain data integrity constraints are met, rather than letting an RDBMS do it for you. Not only that, you will indeed greatly increase your memory footprint, and that footprint will grow as the usage of your application grows to the point where you can't keep everything in memory at all times.
If you already have performance problems...then there are other ways to solve them...such as scaling out your hardware (better hardware, more servers, etc.) If you do not have performance problems yet, and are trying to preemptively solve possible performance problems...don't bother. It is difficult to predict what may cause performance problems, and caching isn't always the best solution, and should generally not be the first. You can gain much more in terms of performance improvements for less cost by adding hardware than by increasing the complexity of your code.
|
|
|
|
|