|
Are you looking for System.Windows.Forms.SendKeys.Send ? You don't need to import to do that.
|
|
|
|
|
1. Put a breakpoint at the line: if(condition) .
2. Run your code.
3. When the breakpoint is hit, press F10. If the control goes to line:SendKeys.Send("^{ESC}");
Then the start menu will be displayed.
4. If control does not goes to that line, then condition is false and hence the start menu will not be displayed.
There is no need to import User32 for this. SendKeys is a class in System.Windows.Forms namespace.
|
|
|
|
|
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
textBox1.Focus();<br />
SendKeys.Send("E");<br />
SendKeys.Send("^(ESC)");<br />
<br />
}<br />
i put a breakpoint at SendKeys.Send("^(ESC)") but then the system hangs and i have to take taskmanager to stop the execution
but the SendKeys.Send("E") is working...(displays E on textbox)
This code was posted by me...
|
|
|
|
|
|
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,
UIntPtr dwExtraInfo);
private void btnInvokeStartButton_Click(object sender, EventArgs e)
{
const int VK_CONTROL = 17;
const int VK_ESCAPE = 27;
const int VK_LWIN = 91;
const int VK_RWIN = 92;
const uint KEYEVENTF_KEYDOWN = 0;
const uint KEYEVENTF_KEYUP = 2;
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYDOWN, (UIntPtr)0);
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, (UIntPtr)0);
}
modified on Monday, July 13, 2009 8:38 AM
|
|
|
|
|
I am afraid but I had to vote you since SendKeys.Send("^{ESC") works fine for me and I don't feel any need of using APIs here. Might be missing out on something.
|
|
|
|
|
I just noticed in his another thread that the method he's using is called page_Load.
I'm afraid he's trying to use SendKeys in a Web Application and for that reason he can't make it work.
|
|
|
|
|
Well, for me it's not working, and i'm the one who suggested him to use API. It does not work in C# and it does not work in VB.Net either.
SendKeys.Send("^{ESC}")
Does nothing.
Windows XP.
|
|
|
|
|
That's strange, could be an OS-related issue?
For me it's working using Win7 RC and .NET 3.5.
|
|
|
|
|
I need to increase the scope of double fee and total. The following code doesn't work because fee and total are out of the scope on the writeline.
if (time <= 3)
{
fee = 2;
total = total + fee;
}
I have more if statements involving fee and total but they all will be applied to the following writeline
Console.WriteLine("Current charge: {0:c}, Total receipts: {1:c}", fee, total);
Edit:
I made fee and total a static variable above the main method and now it works even though I set the new value of fee and total inside a block with less scope. I am not sure how this works, but it works, maybe someone can tell me why it works.
modified on Saturday, July 11, 2009 7:11 PM
|
|
|
|
|
Nathan Revka wrote: fee and total are out of the scope on the writeline.
They aren't, at least not in the code that you showed.
|
|
|
|
|
Hi,
I'm not sure what you are doing, but it could be very wrong.
public void someMethod1() {
if (time <= 3) {
int fee = 2;
}
Console.WriteLine("Fee: {0:c}", fee);
}
does not compile since fee does not exist outside the if block.
public void someMethod1() {
int fee = 0;
if (time <= 3) {
int fee = 2;
}
Console.WriteLine("Fee: {0:c}", fee);
}
does compile since fee exists outside the if block AND is guaranteed to hold a value.
int fee;
public void someMethod1() {
fee=0;
if (time <= 3) {
fee = 2;
}
Console.WriteLine("Fee: {0:c}", fee);
}
public void someMethod2() {
fee=0;
if (time <= 2223) {
fee = 2222;
}
Console.WriteLine("Fee: {0:c}", fee);
}
is probably not OK since both methods share a variable they did not intend to share. Both methods could run at the same time (using threads) and confusing each other.
If the data link between those methods is not intended, the methods really should use local variables.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Nathan Revka wrote: I made fee and total a static variable above the main method
Unless you have a particular need for a field to be accessible globaly and not tied to an instance, I would not have it as static.
You mention your Main method, is this a console app? If so, create a seperate class and put stuff in that, and instanciate that class within the main method.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Help me to convert this code in Java into a C# code
import java.io.*;
import java.net.*;
public class simpleServer
{
public static void main(String args[])
{
char EOF = (char)0x00;
try
{
ServerSocket s = new ServerSocket(2055);
System.out.println("Server started. Waiting for connections...");
Socket incoming = s.accept();
BufferedReader data_in = new BufferedReader(
new InputStreamReader(incoming.getInputStream()));
PrintWriter data_out = new PrintWriter(incoming.getOutputStream());
data_out.println("Welcome! type EXIT to quit." + EOF);
data_out.flush();
boolean quit = false;
while (!quit)
{
String msg = data_in.readLine();
if (msg == null) quit = true;
if (!msg.trim().equals("EXIT"))
{
data_out.println("You sayed: <b>" + msg.trim() + "</b>" + EOF);
data_out.flush();
}
else
{
quit = true;
}
}
}
catch (Exception e)
{
System.out.println("Connection lost");
}
}
}
|
|
|
|
|
You forgot to say "pretty please?".
I'm going to sulk, now.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
help me please
|
|
|
|
|
Sure. Show me what you've done yourself, and point out which bits aren't functioning as you expect, and I'll help you fix them.
I'm not however going to do all the work for you.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I have tried in this mode:
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Configuration;
class Server
{
public static void Main()
{
char EOF = (char)0x00;
try
{
IPAddress ipAd = IPAddress.Parse("127.0.0.1");
TcpListener myList = new TcpListener(ipAd, 2055);
myList.Start();
Console.WriteLine("The server is running. Waiting for a connection....");
Socket soc = myList.AcceptSocket();
Stream s = new NetworkStream(soc);
StreamReader sr = new StreamReader(s);
StreamWriter sw = new StreamWriter(s);
sw.WriteLine("Benvenuti sul server! digita EXIT per disconnetterti." + EOF);
sw.Flush();
bool quit = false;
while (!quit)
{
string msg = sr.ReadLine();
if (msg == null) quit = true;
if (msg != "EXIT")
{
sw.WriteLine("Guest: <b>" + msg + "</b>" + EOF);
sw.Flush();
}
else
{
quit = true;
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
|
|
|
|
|
That compiles with no errors or warnings. So, what's the problem?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Why do you need to convert it? Just make it a method and use it, C#.NET allows you to mix languages.
|
|
|
|
|
Hi
I have to search for a string in a binary file using BinaryReader. How can I do this?
I have searched on Google and MSDN but got nothing.
Thanks in advance.
|
|
|
|
|
By opening the file using the BinaryReader [^], and reading from it. You can use the ReadString [^] method to do so. Then compare the data that you read to the data that you're searching.
SimpleData wrote: I have searched on Google and MSDN but got nothing.
In what language did you query Google?
I'm sure there won't be a ready-to-go solution indeed, but you can put the different parts together to form a new solution
"please help in this regard. give the visual basic code for this as soon possible."
|
|
|
|
|
I've searched in English.
I tried doing it with ReadString but as I have said it didn't work.
Here is the code I was using:
FileStream fs = new FileStream("name.exe",FileMode.Open,FileAccess.ReadWrite);
BinaryReader br = new BinaryReader(fs);
string buff = String.Empty;
while(buff != "blablabla")
{
buff = br.ReadString();
if(buff == "blablabla")
Console.WriteLine("Found!");
}
I wrote this string to the end of file with BinaryWriter with this code.
FileStream fs = new FileStream("name.exe",FileMode.Open,FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(bw);
bw.Seek(0,SeekOrigin.End);
bw.Write("blablabla");
When I open the file with an hex editor I can see that my string is there but I can't find it with these codes.
modified on Saturday, July 11, 2009 2:55 PM
|
|
|
|
|
Try something like this;
FileStream fs = new FileStream("C:\\Windows\\System32\\calc.exe", FileMode.Open, FileAccess.ReadWrite);
BinaryReader br = new BinaryReader(fs);
string searchTerm = "manifestVersion";
byte[] file = new byte[fs.Length];
fs.Read(file, 0, (int)fs.Length);
string asText = Encoding.UTF8.GetString(file);
int index = asText.IndexOf(searchTerm);
Console.WriteLine("Found @position: " + index);
Console.WriteLine("'" + asText.Substring(index, searchTerm.Length) + "'");
Console.ReadKey();
"please help in this regard. give the visual basic code for this as soon possible."
modified on Saturday, July 11, 2009 5:23 PM
|
|
|
|
|
Hi,
I don't agree. Your code assumes all the file data is text; if it is, why use a BinaryReader at all? if it isn't, you need to interpret the binary data to locate the parts that are supposed to be strings, then treat those with code similar to yours, making sure to obey the string conventions in the file (length+content, content+NULL, whatever).
And if you don't know the file format, or just want to find everything that might be a string, then you must check for ASCII or Unicode characters explicitly, you can't just feed arbitrry binary data to an Encoder.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|