making program always active (in background)

i have created a program to capture keyboard button that pressed by user, and pass it to TTS (text to speech), so that every button that pressed will be converted into speech. But, i have a problem because this program only capture key from keyboard only when the form of this program is active.

Is there any technique or hint to make this program always get every key that pressed by user, even when this program inactive.


this is how i get the key from keyboard:

###############################################################
procedure ButtonDetect(Sender: TObject; var Result: Boolean);
.
.
.


procedure TForm1.ButtonDetect(Sender: TObject; var Result: Boolean);
begin
if (GetAsyncKeyState(VK_SNAPSHOT)<>0) then begin
Edit7.Text:='PrintScreen'; //Show key that pressed to 'Edit' field
IndoTTS_Say(PChar(Edit7.text)); //tts function to make input (from Edit7) speak
end
else if (GetAsyncKeyState(VK_LSHIFT)<>0) then begin
Edit7.Text:='Left Shift';
IndoTTS_Say(PChar());
end
.
.
.


################################################################

Comments

  • : i have created a program to capture keyboard button that pressed by user, and pass it to TTS (text to speech), so that every button that pressed will be converted into speech. But, i have a problem because this program only capture key from keyboard only when the form of this program is active.
    :
    : Is there any technique or hint to make this program always get every key that pressed by user, even when this program inactive.
    :
    :
    : this is how i get the key from keyboard:
    :
    : ###############################################################
    : procedure ButtonDetect(Sender: TObject; var Result: Boolean);
    : .
    : .
    : .
    :
    :
    : procedure TForm1.ButtonDetect(Sender: TObject; var Result: Boolean);
    : begin
    : if (GetAsyncKeyState(VK_SNAPSHOT)<>0) then begin
    : Edit7.Text:='PrintScreen'; //Show key that pressed to 'Edit' field
    : IndoTTS_Say(PChar(Edit7.text)); //tts function to make input (from Edit7) speak
    : end
    : else if (GetAsyncKeyState(VK_LSHIFT)<>0) then begin
    : Edit7.Text:='Left Shift';
    : IndoTTS_Say(PChar());
    : end
    : .
    : .
    : .
    :
    :
    : ################################################################
    :
    In asm, there's something called interupts. You can hook the keypress and send it to your func.

    Happy coding wishes
    the one and only [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]

  • : : i have created a program to capture keyboard button that pressed by user, and pass it to TTS (text to speech), so that every button that pressed will be converted into speech. But, i have a problem because this program only capture key from keyboard only when the form of this program is active.
    : :
    : : Is there any technique or hint to make this program always get every key that pressed by user, even when this program inactive.
    : :
    : :
    : : this is how i get the key from keyboard:
    : :
    : : ###############################################################
    : : procedure ButtonDetect(Sender: TObject; var Result: Boolean);
    : : .
    : : .
    : : .
    : :
    : :
    : : procedure TForm1.ButtonDetect(Sender: TObject; var Result: Boolean);
    : : begin
    : : if (GetAsyncKeyState(VK_SNAPSHOT)<>0) then begin
    : : Edit7.Text:='PrintScreen'; //Show key that pressed to 'Edit' field
    : : IndoTTS_Say(PChar(Edit7.text)); //tts function to make input (from Edit7) speak
    : : end
    : : else if (GetAsyncKeyState(VK_LSHIFT)<>0) then begin
    : : Edit7.Text:='Left Shift';
    : : IndoTTS_Say(PChar());
    : : end
    : : .
    : : .
    : : .
    : :
    : :
    : : ################################################################
    : :
    : In asm, there's something called interupts. You can hook the keypress and send it to your func.
    :
    : Happy coding wishes
    : the one and only [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]
    :
    :
    You could also use a wh_Keyboard hook. See SetWindowsHookEx() in the help files for more into. The problem with interrupts is that they might be difficult to intergrate into the windows keyboard subsystem.

  • : You could also use a wh_Keyboard hook. See SetWindowsHookEx() in the help files for more into.

    Don't you think wh_Keyboard works as an interupt?

    : The problem with interrupts is that they might be difficult to intergrate into the windows keyboard subsystem.
    :

    Why's that hard? You could just get the key and send it to the default interupt.

    I don't know delphi, but I know how the computer works.
  • :
    : : You could also use a wh_Keyboard hook. See SetWindowsHookEx() in the help files for more into.
    :
    : Don't you think wh_Keyboard works as an interupt?
    :
    : : The problem with interrupts is that they might be difficult to intergrate into the windows keyboard subsystem.
    : :
    :
    : Why's that hard? You could just get the key and send it to the default interupt.
    :
    : I don't know delphi, but I know how the computer works.
    :

    Which platform is used anyway? Dos or Windows?
    SetWindowsHookEx should be used for Windows and hooking interrupts should be used under dos. Then we can discuss further.



  • : Which platform is used anyway? Dos or Windows?
    : SetWindowsHookEx should be used for Windows and hooking interrupts should be used under dos. Then we can discuss further.
    :

    Don't they work the same?
    What's the difference?
    I have never heard of hooking in windows before, but I want to learn.
    Is it possible to do this in other languages as well, like C++?
  • [b][red]This message was edited by anthrax11 at 2005-12-21 8:14:38[/red][/b][hr]
    : :
    : : : Which platform is used anyway? Dos or Windows?
    : : : SetWindowsHookEx should be used for Windows and hooking interrupts should be used under dos. Then we can discuss further.
    : : :
    : :
    : : Don't they work the same?
    : : What's the difference?
    :
    : [blue]I'm no expert at this, but as I have understood, interrupts don't work under protected mode operating systems such as 32-bit windows. In the MenuetOS source code, there was a table showing how memory is used, and the first 400 bytes were not the interrupt descriptor table, but they were used for other purposes(window information). Interrupts are probably emulated for dos programs.
    : But I might be all wrong, because why else can we see the Interrupt Request settings from the Control Panel-System. For dos programs? Don't know.
    : If we are talking about a dos program right now, then hooking ints is surely the way to go.
    :
    : In windows, calls are made to absolute addresses to whereever the Windows API functions are loaded. Try debugging a small windows program(preferably written in assembly) with OllyDebug to see how that works.
    Interrupts need a special table(IDT) to know where to jump to.
    The entries in the table are not absolute(they are seg:offs). This is not exactly absolute addressing-friendly.
    [/blue]
    :
    : : I have never heard of hooking in windows before, but I want to learn.
    :
    : [blue]I advise you to download a Winapi reference and look up SetWindowsHookEx.
    : The function itself is something like this:
    : [code]
    : SetWindowsHookEx(
    : WH_KEYBOARD, //Type of hook
    : Hook_procedure_ptr, //Pointer to the hook procedure
    : hMod, //identifies the DLL containing the hook proc
    : dwThreadID //0 if the hook isn't associated to any
    : //particular thread.
    : //Otherwise, this is a thread identifier
    : //and hMod is 0
    : [/code]
    :
    : I got an excellent reference from this page:
    : http://ghirai.com/hutch/mmi.html
    : It's a little outdated, but is still very extensive and thorough.[/blue]
    :
    : : Is it possible to do this in other languages as well, like C++?
    :
    : [blue]It is possible to do this in other languages, so long as you can call the windows api.
    :
    : I found some reading material about Winapi hooks with delphi - http://delphi.about.com/library/bluc/text/uc063001a.htm
    :
    : I hope this post makes sense:)
    : [/blue]
    :



  • Thanks, that explained a lot.

    Happy coding wishes
    the one and only [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]

  • :
    : : You could also use a wh_Keyboard hook. See SetWindowsHookEx() in the help files for more into.
    :
    : Don't you think wh_Keyboard works as an interupt?
    :
    : : The problem with interrupts is that they might be difficult to intergrate into the windows keyboard subsystem.
    : :
    :
    : Why's that hard? You could just get the key and send it to the default interupt.
    :
    : I don't know delphi, but I know how the computer works.
    :
    In win9x you can use interrupts without much trouble, but under win2k and upwards the program needs SYSTEM authorization to use interrupts. Since the SYSTEM authorization is the highest level of authorization (even above admin), it is very well protected and normally only used for kernel processes and not for user created processes. The coding itself doesn't make it that hard, but the registration as a SYSTEM process does.
Sign In or Register to comment.

Howdy, Stranger!

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

Categories