Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Capturing Global Key Events

WukkuanWukkuan Posts: 1Member
Does anybody know how to capture global key events in c#? So that no matter what program is in focus, my program will be notified of all of the keys.

My intention is to write a program similar to Project Dolphin, for those faimiliar with it ( http://project-dolphin.net ). It basically takes all keys hit and counts them, then periodically uploads that number to a central server so that people can compare the data to each other and whatnot.

Comments

  • bpwtrbpwtr Posts: 5Member
    [b][red]This message was edited by bpwtr at 2003-6-24 7:5:14[/red][/b][hr]
    [b][red]This message was edited by bpwtr at 2003-6-24 4:40:20[/red][/b][hr]
    : Does anybody know how to capture global key events in c#? So that no matter what program is in focus, my program will be notified of all of the keys.
    :
    : My intention is to write a program similar to Project Dolphin, for those faimiliar with it ( http://project-dolphin.net ). It basically takes all keys hit and counts them, then periodically uploads that number to a central server so that people can compare the data to each other and whatnot.
    :


    i have exact the same question
    i had a solution from "keyspy". but it was written in pascal or something)

    link : http://delphi.icm.edu.pl/ftp/d10free/INDEX (change INDEX with keyspy.zip for file).

    i changed all code so it would work in cbuilder. but exactly the place where the key should get read wont work. couse it is in assembler.
    (it would crash with a "privilige" error.
    perhaps it helps you, perhaps it wont :D

    [code]
    //programma looks for focused window, title etc.but wont use that for this Key extraction.
    //Key was declareerd a Byte in keyspy.pas . i tryed all types...
    asm
    in al, 60h
    mov Key, al
    end;

    if Key = 170 then
    {
    Key = 84;
    LShiftUp = True;
    }
    if (Key != OldKey)
    {
    OldKey = Key;
    if (Key <= 88)
    etc........[/code]

    so...i changed the whole keyspy.zip so it would work in cbuilder. but it just wont work. if you need my converted project, ill mail it to you. less work for you, but it wont work

    [edit]Changed Url[/edit]

  • pingpongpingpong Posts: 937Member
    You need to write what they call a system wide hook.

    This involves using the SetWindowsHookEx API with the WH_KEYBOARD (or WH_KEYBOARD_LL) hook. You should put your code in a DLL (to be able to load it in any process space) and involves setting up a shared data segment.

    All the above is pure win32 system programming, I cannot see why you want to use C# with that. You might be able to pull it off with the appropriate PInvoke calls but your ".NET" DLL will be unmanaged and unsafe, so why bother? Stick with normal C/C++ and vanilla Win32 API.

    : Does anybody know how to capture global key events in c#? So that no matter what program is in focus, my program will be notified of all of the keys.
    :
    : My intention is to write a program similar to Project Dolphin, for those faimiliar with it ( http://project-dolphin.net ). It basically takes all keys hit and counts them, then periodically uploads that number to a central server so that people can compare the data to each other and whatnot.
    :

Sign In or Register to comment.