Click here to Skip to main content
15,886,701 members
Home / Discussions / C#
   

C#

 
Questionneed help. No error in code but not getting output. here is my code. trying to accessing data from active directory. Pin
rahul38420-Oct-15 17:31
rahul38420-Oct-15 17:31 
AnswerRe: need help. No error in code but not getting output. here is my code. trying to accessing data from active directory. Pin
Richard MacCutchan20-Oct-15 21:38
mveRichard MacCutchan20-Oct-15 21:38 
AnswerRe: need help. No error in code but not getting output. here is my code. trying to accessing data from active directory. Pin
Richard Deeming21-Oct-15 1:48
mveRichard Deeming21-Oct-15 1:48 
QuestionWindows Remote Application is not working Pin
Josephss7318-Oct-15 22:35
Josephss7318-Oct-15 22:35 
QuestionHow should I access share folder from server Pin
Member 1201610618-Oct-15 21:10
Member 1201610618-Oct-15 21:10 
AnswerRe: How should I access share folder from server Pin
OriginalGriff18-Oct-15 23:12
mveOriginalGriff18-Oct-15 23:12 
Question[WIN2D] Randomly generated 2D drawing Pin
Member 858597418-Oct-15 14:10
Member 858597418-Oct-15 14:10 
Questionc# delegates and events Pin
Lillepige17-Oct-15 6:06
Lillepige17-Oct-15 6:06 
Hi everyone,

I am learning delegates at the moment. I am trying to implement a keylogger for fun (found online)! Other examples work fine, but here I am lacking experience. However it seems, the method HookFunc is never reached.

I call it in the main method with

KeyboardHook keylogger = new KeyboardHook();
Shouldnt Install() give me output in the command box in the HookFunc method?

My Code:

public enum VKeys
{ 
   KEY_0 = 0x30,       // 0 key ... and others implemented in       //enum
}

public KeyboardHook()
{
	Install();
}

private delegate IntPtr KeyboardHookHandler(int nCode, IntPtr wParam, IntPtr lParam);
private KeyboardHookHandler hookHandler;


public delegate void KeyboardHookCallback(VKeys key);

#region Events
public event KeyboardHookCallback KeyDown;
public event KeyboardHookCallback KeyUp;
#endregion

private IntPtr hookID = IntPtr.Zero;


public void Install()
{
	hookHandler = HookFunc;
	hookID = SetHook(hookHandler);
}

public void Uninstall()
{
	UnhookWindowsHookEx(hookID);
}

private IntPtr SetHook(KeyboardHookHandler proc)
{
	Console.WriteLine("HookID: " + hookID.ToString());

	using (ProcessModule module = Process.GetCurrentProcess().MainModule)
		return SetWindowsHookEx(13, proc, GetModuleHandle(module.ModuleName), 0);
}

private IntPtr HookFunc(int nCode, IntPtr wParam, IntPtr lParam)
{
	Console.WriteLine("HookID 2: " + hookID.ToString());
		if (nCode >= 0)
		{
			int iwParam = wParam.ToInt32();

			if ((iwParam == WM_KEYDOWN || iwParam == WM_SYSKEYDOWN))
				if (KeyDown != null)
					KeyDown((VKeys)Marshal.ReadInt32(lParam));
			int vkCode = Marshal.ReadInt32(lParam);

			if ((iwParam == WM_KEYUP || iwParam == WM_SYSKEYUP))
				if (KeyUp != null)
					KeyUp((VKeys)Marshal.ReadInt32(lParam));
			vkCode = Marshal.ReadInt32(lParam);

		}
		else
		{
			;
		}

		return CallNextHookEx(hookID, nCode, wParam, lParam);
}

AnswerRe: c# delegates and events Pin
BillWoodruff17-Oct-15 6:25
professionalBillWoodruff17-Oct-15 6:25 
QuestionImplement my own IFormatProvider class Pin
Member 905073117-Oct-15 5:29
Member 905073117-Oct-15 5:29 
SuggestionRe: Eigene IFormatProvider implemetieren Pin
Jochen Arndt17-Oct-15 6:14
professionalJochen Arndt17-Oct-15 6:14 
AnswerRe: Eigene IFormatProvider implemetieren Pin
Dave Kreskowiak17-Oct-15 6:29
mveDave Kreskowiak17-Oct-15 6:29 
QuestionRe: Implement my own IFormatProvider class Pin
Maciej Los18-Oct-15 7:56
mveMaciej Los18-Oct-15 7:56 
QuestionFastest way to modify the value in the dictionary Pin
Gilbert Consellado16-Oct-15 12:51
professionalGilbert Consellado16-Oct-15 12:51 
AnswerRe: Fastest way to modify the value in the dictionary Pin
BillWoodruff16-Oct-15 21:54
professionalBillWoodruff16-Oct-15 21:54 
GeneralRe: Fastest way to modify the value in the dictionary Pin
Gilbert Consellado17-Oct-15 19:01
professionalGilbert Consellado17-Oct-15 19:01 
QuestionCreating Events with Dynamically created ComboBox(es) Pin
KakitaIppatsu16-Oct-15 11:30
KakitaIppatsu16-Oct-15 11:30 
AnswerRe: Creating Events with Dynamically created ComboBox(es) Pin
Brisingr Aerowing16-Oct-15 15:32
professionalBrisingr Aerowing16-Oct-15 15:32 
AnswerRe: Creating Events with Dynamically created ComboBox(es) Pin
BillWoodruff16-Oct-15 22:14
professionalBillWoodruff16-Oct-15 22:14 
GeneralRe: Creating Events with Dynamically created ComboBox(es) Pin
KakitaIppatsu20-Oct-15 9:02
KakitaIppatsu20-Oct-15 9:02 
AnswerRe: Creating Events with Dynamically created ComboBox(es) Pin
NeillJam18-Oct-15 22:02
NeillJam18-Oct-15 22:02 
AnswerRe: Creating Events with Dynamically created ComboBox(es) Pin
Foothill19-Oct-15 11:19
professionalFoothill19-Oct-15 11:19 
GeneralRe: Creating Events with Dynamically created ComboBox(es) Pin
Pete O'Hanlon19-Oct-15 22:52
mvePete O'Hanlon19-Oct-15 22:52 
GeneralRe: Creating Events with Dynamically created ComboBox(es) Pin
Foothill20-Oct-15 3:58
professionalFoothill20-Oct-15 3:58 
QuestionHow to resolve network related or instance specific error Pin
Member 1200209515-Oct-15 20:26
Member 1200209515-Oct-15 20: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.