|
Try setting the Form.KeyPreview property to true - if you don't, then the other controls get "first dibs" on the keyboard data.
If that doesn't work, then override the Form ProcessCmdKey method - you should be able to detect it there.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hey buddy! Thanks.
Here is what I have tried. It's not working though except that it sends Ö and close the program. However, when I comment out this.Close(), the program does not put the above character on ms word. Is there anything I'm not doing right? I intent to use switch & cases if I can get it working this way.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Escape)
{
this.Close();
SendKeys.Send("Ö");
return true;
}
else
{
return base.ProcessCmdKey(ref msg, keyData);
}
}
|
|
|
|
|
You aren't sending anything to Word - you are sending it to your application...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hello OriginalGriff,
My intention is to send something to applications such as word, notepad etc. etc.
In my code, i have the SendKeys.Send() to send out relevant to the above applications. I'm not sure if it's right in this case, but it works for sending characters when buttons are clicked.
Here below are the main methods. What should I really do here? How should I send it to the Ms Word please?
protected override CreateParams CreateParams
{
get
{
CreateParams param = base.CreateParams;
param.ExStyle |=0x08000000;
return param;
}
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
switch (keyData)
{
case Keys.Q:
SendKeys.Send("Ɣ");
break;
}
return base.ProcessCmdKey(ref msg, keyData);
}
modified 8-May-16 6:08am.
|
|
|
|
|
SendKeys sends to the active application - which if your app is receiving the keyboard input is your app, not Word or Notepad.
Providing an onscreen keyboard that "interfaces" between the user and any other app is a much more complex job - and not one I have any experience with. I suspect that you will need to look at Global Hooking to "preview" the keyboard and intercept things, which is not a job for the faint hearted (get it slightly wrong, and your dev system will become very unstable).
I'd be tempted to look at "custom" keyboard layouts instead of hooking: The Microsoft Keyboard Layout Creator[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
With your link, I can see a whole lot of pranks in the offing.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
You know you have a low and crude sense of humour!
I feels sorry for the next bloke who does not lock his PC before dissappearing out the door
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi, I finally got something working with keyboard Hooks. However, now both unicode character and the key value of the pressed are being sent. For example, when I pressed Q, I expect to see Ɣ on word, notepad etc. However, I'm getting both i.e. QƔ at the moment. How should I remove the Q and display only the sent character?
private void Form1_Load(object sender, EventArgs e)
{
ghook = new GlobalKeyboardHook();
ghook.KeyDown +=new KeyEventHandler(ghook_KeyDown);
foreach (Keys key in Enum.GetValues(typeof(Keys)))
ghook.HookedKeys.Add(key);
ghook.hook();
}
private void ghook_KeyDown(object sender, KeyEventArgs e)
{
textBox1.Text += ((char)e.KeyValue).ToString();
processKeyPressed((char)(e.KeyCode));
if((char)(e.KeyCode)=='Q')
SendKeys.Send("Ɣ");
}
|
|
|
|
|
I thank you for your response, Original.
I wish we could get this working.
Still believe someone out there would help.
Thanks.
|
|
|
|
|
|
So I basically have a Complex Matrix class like so:
public struct ComplexMatrix
{
private int Rows;
private int Cols;
private Complex[,] matrix;
public ComplexMatrix(int Rows, int Cols)
{
this.Rows = Rows;
this.Cols = Cols;
Complex[,] temp = new Complex[Rows, Cols];
this.matrix = temp;
for (int i = 0; i <= Rows - 1; i++)
{
for (int j = 0; j <= Cols - 1; j++)
{
matrix[i, j] = new Complex(0, 0);
}
}
}
public Complex this[int Row, int Col]
{
get { return matrix[Row, Col]; }
set { matrix[Row, Col] = value;}
}
...
However, Im a bit lazy so I would really like to set matrix items as follows:
MyMatrix[1, 1] = new Complex(1, 0);
MyMatrix[0, 1] = 1;
MyMatrix[1, 0] = 5d;
But I found no easy way of doing this. I basically want the setter of the property to be able to take an object, but the get function will always return a Complex.
I could of curse do this:
public object this[int Row, int Col]
{
get { return matrix[Row, Col]; }
set
{
if (value is Complex)
{
matrix[Row, Col] = (Complex)value;
}
else if (value is double)
{
matrix[Row, Col] = new Complex((double)value, 0);
}
else if (value is int)
{
matrix[Row, Col] = new Complex((double)((int)value), 0);
}
else
{
throw new NotSupportedException("Not supported");
}
}
}
But that is really cumbersome when you want to get the value. Is there any tricks I could use to make this work properly?
|
|
|
|
|
I think I need some Coffee here. The complex class takes care of that for me 
|
|
|
|
|
Just beat me. I was going to suggest looking at Complex constructors taking other numeric types and promoting.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
I don't know if this type of structure (using a List of Lists instead of an Array) is relevant to your concerns, it's something I experimented with some time ago:
public class ComplexMatrix : List<List<Complex>>
{
public ComplexMatrix() { }
public ComplexMatrix(List<List<Complex>> list)
{
foreach(var lst in list) this.Add(lst);
}
public ComplexMatrix(IEnumerable<IEnumerable<Complex>> lstenum)
{
foreach (var lst in lstenum.ToList())
{
this.Add(lst.ToList());
}
}
public ComplexMatrix(int rows, int cols)
{
List<Complex> complexrow;
for (int i = 0; i < rows; i++)
{
complexrow = new List<Complex>(cols);
this.Add(complexrow);
for (int j = 0; j < cols; j++)
{
complexrow.Add(0.0d);
}
}
}
public Complex this[int row, int col]
{
set { this[row][col] = value; }
get { return this[row][col]; }
}
public void SetValue(int row, int col, double real, double imaginary)
{
this[row][col] = new Complex(real, imaginary);
}
} Sample use:
public void Test1()
{
var repeated1 = Enumerable.Repeat(Enumerable.Repeat(new Complex(1, 1), 5), 5);
var repeated2 = Enumerable.Repeat(Enumerable.Range(1, 6).Select(i => new Complex(i,i)), 6);
ComplexMatrix cmatrix0 = new ComplexMatrix(repeated1);
ComplexMatrix cmatrix1 = new ComplexMatrix(repeated2);
ComplexMatrix cmatrix2 = new ComplexMatrix(4,4);
cmatrix2.SetValue(0,0, 34.5, 666.4);
cmatrix2[2,2] = 4.0;
Complex c22 = cmatrix2[2,2];
ComplexMatrix cmatrix3 = new ComplexMatrix
{
{Enumerable.Repeat(new Complex(0.0,0.0), 2).ToList()},
{Enumerable.Repeat(new Complex(0.0,0.0), 2).ToList()}
};
cmatrix3[1, 1] = new Complex(3.4, 45.66);
Complex cmplx = cmatrix3[1, 1];
} Other than an interesting experiment in self-education re Enumerable.Repeat, Enumerable.Range, auto-initializers, and Indexers, etc.: meaning of-it-all is left up to you
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
It's a nice solution, although I prefer the Matlab coding style more, but that seems a bit cumbersome to implement in C#, like so:
var MyMatrix = [1,0,0 ;
0,1,0 ;
0,0,1]
Although I could use my previus developed code to do so:
Evaluate Complex and Real Math Calculator[^]
|
|
|
|
|
I always end up questioning code I wrote (like the example shown here), wondering if it's "too clever by half," if it's just getting "fancy" for a relatively small gain in syntax clarity. And, how about "overhead:" memory use, relative speed ?
My reading of the discussions about Array vs. generic List in .NET re memory and speed from several years ago leaves me with a shaky conviction that using Arrays is a bit more efficient and faster, but, now that .NET has evolved, I'd need to refresh my knowledge of that.
Now, if I could only understand what Complex Numbers were: I mean I can relate in the sense that I often feel I have both an imaginary self as well as a "real" self
cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
Hello,
Why is it necessary to duplicate each string with Substring(0) string.clone when copying strings to cloned object? For int you do not need to copy with int.tryparse(x.tostring()) or similar silliness. Simple assignment operator works but somehow not with strings.
|
|
|
|
|
Can you give us an example of what doesn't work?
It's not clear from your question exactly what you are trying to do and what you expect to happen.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
If I clone object A to object B and use an assignment oprator for all the strings in the .Clone(), Changing the string in object B changes it in object A as well
|
|
|
|
|
Show us the code you are using.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I am working on converting server code from Java to C#.. Not really ASP but pure C# as this serves only text, the frontend server sends my app a request on port 8080 consisting of user's UserAgent and source IP, and my program decides to serve some text for every 1 in 20 or as defined. Its proprietary code
|
|
|
|
|
WorkOnlineClick2Wealth wrote: Changing the string in object B changes it in object A as well
How are you "changing" the string, given that strings in .NET are immutable?
class Foo
{
public string Bar { get; set; }
}
Foo a = new Foo { Bar = "Hello" };
Foo b = new Foo { Bar = a.Bar };
b.Bar = "Goodbye";
Console.WriteLine(a.Bar);
If you can't show us the code you're using, you need to create a small sample project to reproduce the problem and show us that code instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Because, if you look at the specification of String.Clone, it states;
"The return value is not an independent copy of this instance; it is simply another view of the same data. Use the Copy or CopyTo method to create a separate String object with the same value as this instance."
Read https://msdn.microsoft.com/en-us/library/system.string.clone(v=vs.110).aspx
If you also read the specification for; ICloneable Interface (System)[^] it states that ". It does not specify whether the cloning operation performs a deep copy, a shallow copy, or something in between. Nor does it require all property values of the original instance to be copied to the new instance."
Hope that helps..........
|
|
|
|
|
I was using .Substring(0) instead of Copy. And have been looking to know why clone and = do not copy the string. Thank you for the info
|
|
|
|
|
I'm looking for C# chart library that can draw interactive elements in chart. I'm doing a simple xy chart, but i need to draw multiple movable marks(red marks in the picture).
I need to be able to draw them by click, remove them by click, insert them by xy position in the chart, get their xy position. I need the chart with zoom working(mouse and click zoom/unzoom, hand tool). I also need to draw cursors for 4-point and 2-point manual measurement with different length and labels a,b,A,B. Labels are required for red marks for numbering too (1,2,3 ...). The cursors library must be very effective, I use aproximately 16000 data points in one chart.
I've tried MS Chart as a part of Win Forms, but it was very slow. I was able to create marks, but it was very slow under 16000 data points load. I'd rather use WPF instead of Win Forms. I've tried a few open source libraries and there was either no documentation or movable marks missing.
It is a part of my school project. It's OTDR optical trace. picture example how it should look like
Thanks!
|
|
|
|
|