|
Alan Zhao wrote:
What should I have in KeyPress event for each keyboard character?
How complete a keyboard are you emulating?
Anyways, the truly simple way of figuring this out is try it with a keyboard!
However, the right answer (I think) is that you'll want to inject the key-down and key-up messages into the Windows message queue. These keycodes are different (I think) from what you get with KeyPress. The reason for doing it this way is that any control can then receive the key up/down messages from your (I suppose) background thread. It's probably a bit more complicated than I've described, but that's the approach I would start with.
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
|
|
|
|
|
How do you send the messages to Windows message queue and what's Windows message queue?
I am emulating a keyboard with all letters, digits, and a enter key.
Correction: What should I have in MouseDown or Click event b/c the keys are clicked by touch on the screen.
|
|
|
|
|
The Windows message queue is the heart of the Windows operating system, something you really should understand before attempting such a project.
The message queue is just what it (should) sounds like: a queue for messages. A message contains data about the destination window (every control and dialog in Windows is a window), the message you want to send, and to parameters that can point to anything and be used for whatever you like (although the pre-defined Windows messages do define what those should contain in the Platform SDK on MSDN Online[^].
You should read about Windowing[^] to gain a better understanding.
You can also P/Invoke SendInput , which is defined and discussed in the function reference section of another section you should read and understand, Keyboard Input[^]. If you're not familiar with P/Invoke, you should learn[^], but you could also just take a look at http://pinvoke.net/default.aspx/user32.SendInput[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Actually, they are the same, fortunately. This saves work of having to define a separate enum to send keyboard messages and P/Invoke related functions. This is true for the .NET FCL as well - it saves them work, too.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
So how do I sent the keyboard message as if user has press the key on keyboard when he/she really touchs the mointor.
Thank!
|
|
|
|
|
|
Alan Zhao wrote:
So how do I sent the keyboard message as if user has press the key on keyboard when he/she really touchs the mointor.
You'll need a worker thread monitoring the input from the touch screen. The one's I've used had an RS-232 interface that provided the x, y coordinates of where the user touched. Of course, this had to be de-jittered, tested for a sufficiently long period of touch, and mapped to whatever graphics I had on the screen. Oh yes, and there's a calibration process involved to.
Sounds like you're in some deep water.
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
|
|
|
|
|
Hi, thanks for the help, but I didn't expect it to be this complicated.;)
This on-screen keyboard is written in Visual C#, so each Button represents a key. Therefore, when the user touch the button on the screen, it's like you click the button using mouse. So the SomeKey_Click() event fired. My problem is how do I tell system that SomeKey is pressed without physically type the key.
Thanks again!
|
|
|
|
|
I'm a bit confused as to the state of affairs.
Alan Zhao wrote:
This on-screen keyboard is written in Visual C#, so each Button represents a key.
Is that part working already?
Alan Zhao wrote:
Therefore, when the user touch the button on the screen, it's like you click the button using mouse.
Does that part work too?
Alan Zhao wrote:
So the SomeKey_Click() event fired.
And each button on the screen has an event associated with it, so that when the user touches the screen, the button's Click event fires?
Alan Zhao wrote:
My problem is how do I tell system that SomeKey is pressed without physically type the key.
Heath already answered that question, I thought.
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
|
|
|
|
|
Hi,
I don't want to crosspost, but I'm not sure if I have put the question in the right forum. The original post:
http://www.codeproject.com/script/comments/forums.asp?msg=830163&forumid=12076#xx830163xx[^]
Maybe some of you have encountered the above problem.
In short:
I change a source file of an ASP.NET project
Recompile
- and the assembly isn't updated, nor am I blessed with the usual errormessages if I write something syntaktically wrong - just to provoke the compiler to note a filechange.
but if I delete the assembly and recompile, I do get errormessages / a new assembly.
Even shorter:
- what can make VS.NET 2003 NOT compile a file ? I must be missing something.
UPDATE: A "Rebuild solution" works ! So it must definately be VS that just can't figure out when a code file has changed. Hope this gives you a clue - I'm still lost.
Best regards - and thanks in advance
Jan Hansen
Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert
|
|
|
|
|
On the off chance that this is it--check the file date/time of your source file, vs. your system clock or the assembly.
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
|
|
|
|
|
HA ! That is it. I actually looked at it, but was probably too tired to notice what was really wrong. Heres the situation:
The source files (and assemblies) are placed on a network share, which has never given me problems before. However, when I hit "re-build", the sourcefile is saved with the timestamp of my server (say, 10:11) whereas the assembly is timestamped with the system clock on my client pc (10:15).
Now I can hit "build" as many times as I like until the server time has changed from 10:11 to past 10:15, which will cause the client to rebuild the assembly as the sourcefile is now newer than the assembly.
I've synched the system clocks with "net time \\lonestar /SET /y" and now everything behaves normally again. But I do that everytime I logon (startscript) so the problem must be due to one of the system clocks being rather unprecise.
Anyway, it works - Thanks a lot Marc !
/Jan
Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert
|
|
|
|
|
A lot of times it can also be because someone doesn't have their time zone set correctly, or if your region exhibits Daylight Saving Time, doesn't have the option checked to automatically change the clock (this has to do with time zone offsets that may change with DST). That happens occassionally where I work were email messages seem to come from the future and people get confused.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
One thing that have annoyed me with most languages I've used (including C#) is the problem with returning multiple values from methods.
The following works, but is not very neat, and to my opinion is not very readable:
a = BiteMe(x, y, z, out b, out c);
Look how elegant Lua solves this:
a, b, c = BiteMe(x, y, z);
And notice how easy you can swap variable values in Lua:
a, b = b, a;
Maybe something for the C# language design team.
Regards,
Björn Morén
Stockholm, Sweden
|
|
|
|
|
I've used a language that is like Lua in this respect (it is called Magik and was created by a company called Smallworld in the late 80s).
What I found most annoying was that a method was returing multiple values and I had no idea what order they were in or what they were because the method was named GetX(), but it also returned Y and Z - The compiler would never complain if I missed one, or didn't get the order right, because receiving the return parameters from a method is optional. I kept having to refer to the documentation as it was not intuative as to what was being returned.
At least with C# (and C++/C et al) all these additional parameters are named so it is easy to tell what they represent, and that you have to provide something for them to be received into so you don't accidentatlly miss one.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
I dont think this would be a problem if the syntax for declaring return values would be very similar to declaring input parameters:
public int, string, string BiteMe(float x, float y, float z) { }
or maybe the following is more readable, and maps to xml comments better:
public int a, string b, string c BiteMe(float x, float y, float z)
{
return Convert.ToInt32(x), y.ToString(), z.ToString();
}
Regards,
Björn Morén
Stockholm, Sweden
|
|
|
|
|
bjoernen wrote:
One thing that have annoyed me with most languages I've used (including C#) is the problem with returning multiple values from methods.
Yes, this frustrating for me too. However, I've found that the best way to manage this is to pass a struct (by reference!) or a class (which is automatically by ref). It's better code, more understandable, easier to extend, and gives you a lot of other benefits too.
In fact, I need to go clean up a bunch of code right now that could really use a class instead of discrete parameters!
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
|
|
|
|
|
Yes, I use those too, but under protest.
But I still find it counter-productive to be forced to create output structs. Nobody uses input structs, because the C# language handles a collection of input parameters elegantly. In my mind output result values ought to be handled the same way.
Lets say you have 10 different methods that each return a result object, but from different classes, for instance Point, Rectangle, ArrayList, etc (some of the framework structs and classes). Lets say you also want to be able to tell if the operation went ok, for all those methods, so you'll need a second output parameter of type bool. Would you go about creating 10 output structs to solve that? Or would you use "out"-parameters? Neither is both elegant and productive.
Regards,
Björn Morén
Stockholm, Sweden
|
|
|
|
|
bjoernen wrote:
Nobody uses input structs, because the C# language handles a collection of input parameters elegantly.
Ah, but I disagree. Input structs are very useful too! For example you can have overloaded constructors that accept different parameters and types. You can set defaults, and do validation. An input struct is a very nice middle layer between the caller and the callee.
bjoernen wrote:
Lets say you have 10 different methods that each return a result object, but from different classes, for instance Point, Rectangle, ArrayList, etc (some of the framework structs and classes). Lets say you also want to be able to tell if the operation went ok, for all those methods, so you'll need a second output parameter of type bool. Would you go about creating 10 output structs to solve that? Or would you use "out"-parameters? Neither is both elegant and productive.
In practice, no. But in theory, if I were to really apply my own rules of programming to myself 100% of the time, then yes, I'd create different structs. And I'd make the methods consistent, so that they return a bool, indicating success (although I suppose throwing an exception is the neuveau way now, blech).
IMO, the problem, here, is that for all the cool features of something like Visual Studio, it does very little to help in good implementation. If you had a tool that would automatically create the structs for you, then it would be easy and accepted practice. And then, if you needed to modify the struct, you wouldn't have to fix up 10's or 100's of callers to match the new method signature, or create an abortion of overload methods. Obviously though, there is a line between practical and silly. Unfortunately, there are no good guidelines. The current state of [edit]Computer Science[/edit] is a joke, IMO, but that's another matter. It's just that your question has touched on this subject, which is something I like to get up on my soapbox and rant about.
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
|
|
|
|
|
Marc Clifton wrote:
Ah, but I disagree. Input structs are very useful too! For example you can have overloaded constructors that accept different parameters and types. You can set defaults, and do validation. An input struct is a very nice middle layer between the caller and the callee.
I've done projects using both designs (simple parameters vs input structs), and I can't see the advantage of input structs. Input structs are usually very specific; they are used for a specific method. Since all mechanisms you describe can be accomplished with/within methods too (overloaded methods and validation inside methods, etc), I see no use of encapsulating the call parameters, just for sake of encapsulation.
Some people argue that it is easier extend the design by adding a parameter to the struct, than it is to the method signature. Just because of this, I would say it tampers with readability. I'll have to look at both method signature and struct to understand how to call this method.
I would say that a method should accept a struct only if the struct exists on it's own merits. For instance, it makes no sense to send x, y, width and height when Rectangle exists.
Marc Clifton wrote:
If you had a tool that would automatically create the structs for you, then it would be easy and accepted practice. And then, if you needed to modify the struct, you wouldn't have to fix up 10's or 100's of callers to match the new method signature, or create an abortion of overload methods
I agree that such tool would be very valuable. But I cant see why for example adding a property to a struct (which gets a default value so it wont break 100 callers) is less work than adding an overloaded method that takes another parameter to the class. The lack of support for optional method parameters in C# is another issue.
Marc Clifton wrote:
The current state of [edit]Computer Science[/edit] is a joke, IMO, but that's another matter. It's just that your question has touched on this subject, which is something I like to get up on my soapbox and rant about.
I was pleasantly surprised with the whole .NET initiative at first, and I have to say that C# is a good improvement over Java, and a huge over C++. I will definately stick with it. But I would have liked to see a bigger "generation leap". Especially on the algorithms and patterns department. What we got is a consitent win API, fancier tools and a few new ones. We still code apps the same way.
I would like to reduce the detail work by having the development environment support many abstract concepts like Hierarchical State Machines and GOF patterns, and let me describe logic in a declarative way, much like Prolog or Lisp. The programmer should not be dealing with implementation details (unless he wants to), but just enforce architectural rules (patterns) and business rules (declarative clauses).
Regards,
Björn Morén
Stockholm, Sweden
|
|
|
|
|
And structs are allocated on the stack, making them excellent for short-time use. A collection is a reference type and is allocated on the heap. The GC will get around to collecting it when it sees fit (and you should rarely force the GC through GC.Collect because it's a synchronous operation). That's a big waste for passing parameter data that is used within the method call and for nothing else (potentially).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You could just create a struct class(es) Tuple2(...9) and just return that. eg
Tuple3 t = BiteMe(x,y,z);
Alternatively I use:
void BiteMe(out x, out y, out z)
top secret xacc-ide 0.0.1
|
|
|
|
|
C# has nothing to do with it. A single return value is defined in the Common Language Infrastructure, or CLI. This is what defines the Common Intermediate Language (CIL), the Common Language Runtime (CLR), the Common Language System (CLS), and more. C# complies to that specification making it one of many languages that can interoperate with each other through Intermediate Language, or simply IL. To change one you'd have to change the entire specification, and I don't see that happening.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Since out parameters exist, I can't see why Lua-style multiple return values would be difficult to implement in the C# language. In it's rude form it could translate Lua-style method return syntax to the "out"-syntax.
Calling:
int a;<br />
int b;<br />
int c;<br />
a, b, c = BiteMe(x, y, z);
before compilation translates to ->
int a;<br />
int b;<br />
int c;<br />
BiteMe(x, y, z, out a, out b, out c);
Declaring:
public int a, int b, int c BiteMe(int x, int y, int z)<br />
{<br />
return x, y, z;<br />
}
before compilation translates to ->
public void BiteMe(int x, int y, int z, out int a, out int b, out int c)<br />
{<br />
a = x;<br />
b = y;<br />
c = z;<br />
}
Regards,
Björn Morén
Stockholm, Sweden
|
|
|
|
|
Python allows similar multiple function
returns and assignments.
As the Python developers will tell you,
they are mearly implemented as "syntactic
sugar." There's no need for such to
bleed down to the lower implementation
level in this case either.
I've only been messing with C# for a short
time but since I tend to use a lot of Win32
API calls more than multiple assignment I'd
find useful a tool where I could put the
cursor on one of those all caps DEFINES
and have it paste in a const with the correct
value from one of the Windows.h includes.
Hunting that stuff down and typing in
const declarations is the pits!
What a waste of time!
|
|
|
|
|