|
Hello,
I have created a windows service in c#. I would like to use windows service and print the "x" value in the active window wherever the cursor located. I have used Keybd_event to print the value. Unfortunately i am unable to see the value in the active window. I assume Keybd_event is not fired. I have added log messages before and after keybd_event event, log messages are creating perfectly. However if i use the same code to print the value from an windows application i am able to print the value. I am attaching my code whatever i have used to print the value
Here is the code i have used in windows service and application
using System;
using System.Collections.Generic;
using System.Text;
namespace SmartcardLibrary
{
public class PrintToScreen : KeyboardEvents
{
private static log4net.ILog logError = log4net.LogManager.GetLogger("SmartCardErrorLogger");
private const string NEW_LINE = "\n";
private const uint KEYEVENTFKEYUP = 0x2;
private const byte VKCAPSLOCK = 0x14;
private const byte SCCAPSLOCK = 0xBA;
private const byte VKTAB = 0x09;
private const byte SCTAB = 0x8F;
public static void Print(string input)
{
try
{
//logError.Error("PRINT SCREEN TAG ID: " + input + NEW_LINE);
input = input.ToUpper();
byte[] virtualKey = Encoding.UTF8.GetBytes(input);
byte[] bScanCode = new byte[input.Length];
for (int count = 0; count < virtualKey.Length; count++)
{
bScanCode[count] = ScanCode(virtualKey[count]);
}
for (int i = 0; i < virtualKey.Length; i++)
{
if (GetKeyState(VKCAPSLOCK) == 0)
keybd_event(VKCAPSLOCK, SCCAPSLOCK, 0, 0); //Caps Lock Press Event
keybd_event(virtualKey[i], bScanCode[i], 0, 0); //Key press event
//UnsafeNativeMethods.keybd_event(virtualKey[i], bScanCode[i], KEYEVENTF_KEYUP, 0); //Key release event
//UnsafeNativeMethods.keybd_event(VKCAPSLOCK, SCCAPSLOCK, KEYEVENTFKEYUP, 0); //Caps Lock release Event
}
keybd_event(VKTAB, SCTAB, 0, 0); //Tab press event
//logError.Error(input + NEW_LINE + NEW_LINE);
}
catch (Exception ex)
{
logError.Error(ex.Message + NEW_LINE + ex.StackTrace);
}
}
private static byte ScanCode(byte Character)
{
byte result = Convert.ToByte(MapVirtualKey(Character, 0x1)); //0x1 indicates VirtualCode to Scan code conversion
return result;
}
}///
}///
This code is working for application but not working for windows service...
your suggestions on this issue would be appreciated
|
|
|
|
|
Ummm... your Windows Service has an "active window"?
You probably don't want a Windows Service; won't a simple thread suffice?
What are you trying to do?
|
|
|
|
|
Hi,
I am building a web browser in C#.I am required to dynamically edit the Html Page currently displayed and add a javacript to it.How do i go about it?
After adding,how do I invoke this javascript?
Thanks in advance.....
|
|
|
|
|
You can add Javascript using the ClientScript.RegisterClientScriptBlock() method. You can also make sure the script is not already registered for the page by checking the ClientScript.IsClientScriptBlockRegistered property.
You can invoke the method by either adding a onload attribute to the body tag of your page, or just by calling a function in your javascript.
|
|
|
|
|
Which object exactly exposes this method ClientScript.RegisterClientScriptBlock()?
Am i missing any references in the project? namely System.Xml?
|
|
|
|
|
It's part of the Page class, and this assumes that you are doing this as an ASP.NET page. If you are doing this, then you should really have posted this in the ASP.NET forum.
|
|
|
|
|
Let me be clear enough!I am implementing a web browser in C#.
I need to dynamically change the page currently displayed on a web browser for example I want certain part of the page to be highlighted.
So I am not related to ASP.NET at all.
I think my subject line is the source of misguidance!
Any suggestions for my problem??
|
|
|
|
|
You can always gain access to the Html document through your web browser and then add the javascript to the DOM. This[^] article should give you an idea - but be aware that the webbrowser doesn't expose the IHtmlDocument2 as it stands. In .NET 2, you have to do some work to get the interface.
|
|
|
|
|
I havent been able figure out a way to find the IHTMLDocument interface....
Can u help me out with it???
|
|
|
|
|
From memory - you need to add a reference to MSHTML from Add references... (COM tab). Once you have this referenced in your project you should be able to do this:
IHTMLDocument2 doc = (IHTMLDocument2) webBrowser.Document.DomDocument; As I said, I'm doing this from memory so I apologise if it's MSHTML2 or something like that in the references dialog.
|
|
|
|
|
The method seems to be absolutely fine.....But
How do I add parameters to the javascript which i want to invoke?
Thanks In advance for getting me till here...
|
|
|
|
|
Suppose you have a method called setCanvas that you want to pass a particular div to, you would code this as function setCanvas(div){ /* Do Something */} in the page. Now, to call it dynamically you could use
IHMTLDocument2 doc = (IHTMLDocument2) webBroswer.Document;
if (doc != null)
{
IHTMLWindow2 wind = doc.parentWindow;
string code = "setCanvas('divItem');"
if (wind != null)
wind.execScript(code, "javascript");
}
|
|
|
|
|
string s = File.ReadAllText("s.txt");
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)webBrowser1.Document.DomDocument;
if (doc != null)
{
mshtml.IHTMLWindow2 windowx = doc.parentWindow;
if (windowx != null)
{
windowx.execScript(s, "javascript");
}
}
The file s holds a javascript which i want to run plus it takes some arguments to it too....
but it gives me some exception of HRESULT ....can u plz point out the problem
|
|
|
|
|
Aditya Baraya wrote: can u plz point out the problem
Without knowing what the code you were executing actually was, and without knowing the HRESULT then no I can't.
|
|
|
|
|
string s = "alert(hi);";
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)webBrowser1.Document.DomDocument;
if (doc != null)
{
mshtml.IHTMLWindow2 windowx = doc.parentWindow;
if (windowx != null)
{
windowx.execScript(s, "javascript");
}
}
The following code is called on a button click event
So I get an exception HRESULT:0x80020101...
Can you plz help me out with this error?
|
|
|
|
|
How do people keep track of build numbers in .net
I've got a project in VS2005 with a deployment project and I'd like to create sequentially numbered releases to keep track of things. This used to be pretty easy in the old VB6 days.
I've found various snippets of code for VS macros that i'm currently trying to get to work but was interested to know what other people do
Does anyone know what the rationale behind non-sequential numbering for versions was?
Russell
|
|
|
|
|
In your AssemblyInfo.cs class, there's a version attribute [assembly: AssemblyVersion("1.0.0.0")] . If you want to increment a part of it automatically on each build, just replace the relevant part with *. So you would end up with [assembly: AssemblyVersion("1.0.0.*")] which automatically increments the * portion on each build.
|
|
|
|
|
Thanks for the reply Pete, I'd tried using that before and it just seems to create a random number, am i missing something?
I'd like to be able to say issue x fixed in version 1.0.0.y and above but the random element makes that impossible.
Thanks,
Russell
|
|
|
|
|
What makes you think its random? Does it ever decrease with a buld?
AFAIK it increments once per build - so separate releases you make will probably have different (but ultimatly increased) number.
|
|
|
|
|
You are correct. Every time you build, the number is incremented.
|
|
|
|
|
That you for confirming that O Sarcastic One.
* bows while stepping backwards *
|
|
|
|
|
J4amieC wrote: That you for confirming that O Sarcastic One.
* bows while stepping backwards *
Sorry - I wasn't actually being sarcastic. I just hoped that the OP would follow the thread and find the confirmation. I would not be sarcastic with a chap of your calibre.
|
|
|
|
|
I was just tugging your chain. The irony was that my response was a thousand times more sarcastic than your response.
|
|
|
|
|
Pete O'Hanlon wrote: the number is incremented
IMO that's both true and misleading.
increment as in "make larger" or "add something positive to it" is correct,
but to a lot of people, myself included, increment means "add one" as is common
in most microprocessor instruction sets.
so maybe the better explanation is AssemblyVersion x.y.z.* or x.y.*.*
generates automatic numbers that contain datetime information in such a way
that the entire number gets increased each time.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- 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 PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Luc Pattyn wrote: IMO that's both true and misleading.
increment as in "make larger" or "add something positive to it" is correct,
but to a lot of people, myself included, increment means "add one" as is common
in most microprocessor instruction sets.
No excuses Luc. I grant you that one. I should have used increased.
|
|
|
|