Click here to Skip to main content
15,913,836 members
Home / Discussions / C#
   

C#

 
GeneralRe: Games In C# Pin
MarkB77726-Mar-08 0:22
MarkB77726-Mar-08 0:22 
GeneralRe: Games In C# Pin
Krazy Programmer26-Mar-08 0:29
Krazy Programmer26-Mar-08 0:29 
GeneralRe: Games In C# Pin
papadimitriou26-Mar-08 0:48
papadimitriou26-Mar-08 0:48 
GeneralRe: Games In C# Pin
Pete O'Hanlon26-Mar-08 0:52
mvePete O'Hanlon26-Mar-08 0:52 
GeneralRe: Games In C# Pin
Krazy Programmer26-Mar-08 2:14
Krazy Programmer26-Mar-08 2:14 
GeneralRe: Games In C# Pin
GuyThiebaut26-Mar-08 2:45
professionalGuyThiebaut26-Mar-08 2:45 
JokeRe: Games In C# Pin
PIEBALDconsult26-Mar-08 7:29
mvePIEBALDconsult26-Mar-08 7:29 
Questionc# windows service is not raising keybd_event to print the value into active window Pin
yaswanth25-Mar-08 23:08
yaswanth25-Mar-08 23:08 
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
GeneralRe: c# windows service is not raising keybd_event to print the value into active window Pin
PIEBALDconsult26-Mar-08 7:31
mvePIEBALDconsult26-Mar-08 7:31 
GeneralDynamically adding Javascript to the Html Page. Pin
Aditya Baraya25-Mar-08 23:04
Aditya Baraya25-Mar-08 23:04 
GeneralRe: Dynamically adding Javascript to the Html Page. Pin
Eduard Keilholz25-Mar-08 23:35
Eduard Keilholz25-Mar-08 23:35 
GeneralRe: Dynamically adding Javascript to the Html Page. Pin
Aditya Baraya26-Mar-08 0:44
Aditya Baraya26-Mar-08 0:44 
GeneralRe: Dynamically adding Javascript to the Html Page. Pin
Pete O'Hanlon26-Mar-08 0:54
mvePete O'Hanlon26-Mar-08 0:54 
GeneralRe: Dynamically adding Javascript to the Html Page. Pin
Aditya Baraya26-Mar-08 1:15
Aditya Baraya26-Mar-08 1:15 
GeneralRe: Dynamically adding Javascript to the Html Page. Pin
Pete O'Hanlon26-Mar-08 2:25
mvePete O'Hanlon26-Mar-08 2:25 
GeneralRe: Dynamically adding Javascript to the Html Page. Pin
Aditya Baraya26-Mar-08 7:43
Aditya Baraya26-Mar-08 7:43 
GeneralRe: Dynamically adding Javascript to the Html Page. Pin
Pete O'Hanlon26-Mar-08 10:03
mvePete O'Hanlon26-Mar-08 10:03 
GeneralRe: Dynamically adding Javascript to the Html Page. Pin
Aditya Baraya26-Mar-08 20:41
Aditya Baraya26-Mar-08 20:41 
GeneralRe: Dynamically adding Javascript to the Html Page. Pin
Pete O'Hanlon26-Mar-08 23:13
mvePete O'Hanlon26-Mar-08 23:13 
GeneralRe: Dynamically adding Javascript to the Html Page. Pin
Aditya Baraya27-Mar-08 0:31
Aditya Baraya27-Mar-08 0:31 
GeneralRe: Dynamically adding Javascript to the Html Page. Pin
Pete O'Hanlon27-Mar-08 0:33
mvePete O'Hanlon27-Mar-08 0:33 
GeneralRe: Dynamically adding Javascript to the Html Page. Pin
Aditya Baraya27-Mar-08 0:49
Aditya Baraya27-Mar-08 0:49 
General.net build numbering Pin
Russell Jones25-Mar-08 22:37
Russell Jones25-Mar-08 22:37 
GeneralRe: .net build numbering Pin
Pete O'Hanlon25-Mar-08 22:46
mvePete O'Hanlon25-Mar-08 22:46 
GeneralRe: .net build numbering Pin
Russell Jones25-Mar-08 23:26
Russell Jones25-Mar-08 23:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.