|
Hi all,
i am using a clasic low-level hook for the keyboard and runing it in the main class:
kBHook = new KeyBoardHook();
kBHook.KeyPress+=new KeyPressEventHandler(kBHook_KeyPress);///
kBHook.KeyDown+=new KeyEventHandler(kBHook_KeyDown);
kBHook.KeyUp+=new KeyEventHandler(kBHook_KeyUp);
so KeyBoardHook is another class on my project.
it happens that when my program is busy doing calculations the keyboard class misses KEYUP/KEYDOWN messages.
so my questions are:
1. how can i make another thread that always listen to messages?
2. can i try to hook to keyboard in a way that i will always get the messages (i need my program to get those msgs before others)
Thank you,
R.Z
|
|
|
|
|
I'm not sure about #2, but for #1, the only thing you'll most likely need is to set the apartment state of the thread to STA. You can do this using the SetApartmentState method on the Thread class.
|
|
|
|
|
Hi, thanks for quick reply.
i don't start my program as a Thread t=new Thread...
the program's thread starts like this (and it is STA) :
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
any ideas?
R.Z
|
|
|
|
|
Sounds like the keyboard hook class is not functional. couple things to check: if you're using native Win32 hooks, I assume you have a callback function? Well, your delegate to that function must be manually kept alive, IRRC.
Aside from that, all I can suggest is narrowing the problem down: are you sure it only occurs after work is occurring? Are the events not being sent at all? what happens after the work is completed, do the hooks resume working?
|
|
|
|
|
my keyboard class is supposed to prevent keys from being sent to the current active window.
when there is no heavy work on my program it blocks all chars and Notepad do not show any chars.
when i write (for testing) Thread.Sleep(1000) in the KeyDown event in the main program , Notepad then display the characters even that i blocked them (return 1 on the hook).
i have seen then even if my Hook gets the message later, the Notepad already displaying the char.
this is the main core of the listening:
KeyboardHookProcedure = new HookProc(KeyboardHookProc);
hKeyboardHook = SetWindowsHookEx( WH_KEYBOARD_LL, KeyboardHookProcedure, Marshal.GetHINSTANCE( Assembly.GetExecutingAssembly().GetModules()[0]),0);
the SetWindowsHookEx defined like that:
[DllImport("user32.dll", harSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall, etLastError=true)]
private static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
Whats is IRRC and how do i do that?
Thanks,
R.Z
|
|
|
|
|
IIRC is "if I recall correctly".
When you pass a delegate instance in for the lpfn parameter of SetWindowsHookEx, make that delegate be a field in your class so that it doesn't get disposed; as I recall, since the object is being passed into a native method, then never used again, the garbage collector cleans up the delegate, causing your hook to fail. So one thing to check is make sure the delegate you pass into SetWindowsHookEx stays alive.
Windows may have some mechanism so that if the process eating the keyboard is not responding (i.e. busy do to lots of work) it may send out the key events to other processes. Can you make your work occur on another thread, thus keeping the hook procedure thread free? That'd be ideal.
|
|
|
|
|
This is the error message:
(0,0): error CS1705: Assembly 'Common, Version=1.0.2516.28982, Culture=neutral, PublicKeyToken=null' uses 'Eng.Common, Version=2.0.1623.14765, Culture=neutral, PublicKeyToken=0989625e39e31c91' which has a higher version than referenced assembly 'Eng.Common, Version=2.0.131.0, Culture=neutral, PublicKeyToken=0989625e39e31c91'
in the object browser it shows both versions of this dll...
How can I overcome this problem?
Thanks,
Jim
|
|
|
|
|
You need to use the version that is matching what your application is looking for. Currently, your application is using version 2.0.131.0 and you are referencing version 2.0.1623.14765!
|
|
|
|
|
Quick question on remoting. If I have a remote object which has a property that is read/write, is there a way to enforce it such that only the host that published the object has write access to a property and only the client has read access. Or vise-versa.
|
|
|
|
|
Are you talking about something like this?
IPrincipal principal = System.Threading.Thread.CurrentPrincipal;
if (! principal.IsInRole(machinename + @"\RemotingUsers"))
{
throw new UnauthorizedAccessException("The user is not in group RemotingUsers");
}
|
|
|
|
|
You can also check the IPFilter example in the sdk.
|
|
|
|
|
Thanks, I'll check it out
|
|
|
|
|
Hello,
I'm using wndproc to detect arrival of an usb device ( usb key ), all is ok but
the time beteewn I can see the windows system detect the key usb ( icon apear in tool bar of desk windows ) and the time where Wndproc receive windows message is like 20 secondes !
why this long time ? how accelerate detection of insert usb key by my programm ?
thank
Vincent
ps : I hope you understand my question
|
|
|
|
|
I am working on a personal money manager in C# and am wondering what I should do with regard to data.
I have some code that I am starting with and currently it uses an XML file to store it's data. The data is then read into memory, uncompressed and then manipulated as required.
Since this single file potentially could contain several Bank accounts, Stock accounts, etc, it could get large. However, probably not more than 5 meg.
Should I read the entire file into memory even though I may not be using all the data?
I am also considering using an SQL database rather than an XML file.
Is an SQL database a better approach than a DataSet with regard to this type of application?
What is the general consensus on using DataSets (i.e., should they only be used for files that are expected to be small in size)? If so, roughly what should that size be?
|
|
|
|
|
SQL might be a good option and Microsoft has a new SQL Server that would work well for this.... http://www.microsoft.com/sql/editions/sqlmobile/default.mspx
It is not just for mobile devices it runs on desktops now too. I started to look at it and it is not what I need for work, but I am debating using it for a personal project.
Steve Maier, MCSD MCAD MCTS
|
|
|
|
|
Thanks for the reply.
I already know of this and several others.
If I use an SQL database, I'm not sure which one I will go with, but I may use the "Minosse" DBMS or "Sharp HSQL" as the source code is available for both.
|
|
|
|
|
That reminds me of when I worked at writing printer drivers. The group that wrote the code that ran on the machine and scheduled things and rendered the pages and the UI for it was all in Java. I asked why use Java and their biggest selling point was that it was portable. So I asked if they were planning to port it to a different platform and they reply that it would never happen because there were kernal changes on Solaris that they put in to make things run and that the guy that did them is no longer working with the company. So they decided to use a nice portable language on a system where porting was not even feasible.
Having the source code to the database really does not do anything for you unless you are going to put in your own things to it - and most people won't. If you are working on something to try to sell to others, there is alot more things to do with website, marketing, support, as well as the programming. Having the source code for the database would just be one more thing that I would be looking at and tweaking and delaying the release of the product..... but on just something that is for your own use it could be fun to look over how they are doing the database and what is behind it. Good Luck.
As for some of the many free databases that are out there, I have played around with a few and some of them did not have very good ADO.NET providers at the time. They keep getting better but it's something to watch out for.
Steve Maier, MCSD MCAD MCTS
|
|
|
|
|
hi all,
I am planning to implement a simple text editor in c#. Can anyone tell how to highlight the syntax after loading a file (which contains c# code) into a richtexbox.
Don't wait to hear a word of thanks from anybody when you help them instead ask them to help three other people and ask them to continue in chain.
|
|
|
|
|
There isn't a built in property. This has to be programmed.
|
|
|
|
|
You have to amend the raw rtf. This is quite a time consuming task.
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
i was able to play a wave file using a buffer object, but i want to check for the sample rate and other things from the wave file, via code, i thought i can do from the buffer object, for example i wanna check for the sample rate if it is 8k then i needed to converted some how to 44k, i know it will not make a difference in quality.
thanks
qkhader
|
|
|
|
|
will you please help me i am a bit confused i am getting controls on forms which are placed directly on form but not those which are placed on a container control
i am using
this.Controls
|
|
|
|
|
I guess you are doing this:
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
foreach (Control ctr in this.Controls)<br />
{<br />
Console.WriteLine(ctr.Name);<br />
} <br />
}
You need to recurse through the controls to check if they contain stuff
private void button2_Click(object sender, EventArgs e)<br />
{<br />
RecurseThroughControls(this.Controls);<br />
}<br />
private void RecurseThroughControls(System.Windows.Forms.Control.ControlCollection concol)<br />
{<br />
foreach (Control ctr in concol)<br />
{<br />
Console.WriteLine(ctr.Name);<br />
RecurseThroughControls(ctr.Controls);<br />
}<br />
}
I hope this solves your problem
Russ
|
|
|
|
|
it did thanks
|
|
|
|
|
I would recommend shortcutting the recursive call by checking ctr.HasControls()
|
|
|
|