PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > how to get raw keyboard input in windows ?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
how to get raw keyboard input in windows ?

Réponse
 
LinkBack Outils de la discussion
Vieux 29/03/2008, 13h07   #1
wbsurfver@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut how to get raw keyboard input in windows ?


I have this program, it just runs and anytime the clipboard changes
and contains some large size,
it run the speech thing through win-sapi. So I can go to any website,
highlight some text and copy it to the clipboard and it will speak the
text. I can't get it to interupt very well. If you hit control-c it
won't
stop until it's done with the text, thus I broke it into lines.

Here's my current problem:
I would like to be able to read raw keyboard data, so that if I hit
spacebar or some function key, it would pause, even if the dos shell
running the program was not in focus. How can I do that ?


-----------------------------------------------------

require 'win32/clipboard'
include Win32
require 'win32ole'


class MySpeech

def initialize

@obj_voice = WIN32OLE.new("SAPI.SpVoice")
@obj_get_voices = @obj_voice.GetVoices

@obj_get_voices.each { |voice| puts voice.GetDescription }

end


def talk(txt)
done = false
lines = txt.split(/$/)
lines.each do |ln|
@obj_voice.speak ln
end
end

def run
prev = Clipboard.data
while true
curr = Clipboard.data
if curr and curr != prev and curr.length > 80
talk curr
prev = curr
end
end
end


end


spkthr = Thread.new do
spk = MySpeech.new
spk.run
end

spkthr.join
  Réponse avec citation
Vieux 29/03/2008, 21h27   #2
Charles Calvert
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to get raw keyboard input in windows ?

On Sat, 29 Mar 2008 05:07:37 -0700, wbsurfver@yahoo.com wrote:

> Here's my current problem:
> I would like to be able to read raw keyboard data, so that if I hit
> spacebar or some function key, it would pause, even if the dos shell
> running the program was not in focus. How can I do that ?


You're trying to do something outside of normal Windows functionality. It
is possible, but difficult and brittle.

Look at the function SetWindowsHookEx here:
<http://msdn2.microsoft.com/en-us/library/ms644990.aspx>. If you specify
0 for the thread ID, you can hook all of the applications and monitor
their keyboard events.

The problem with doing this is that you have to create a DLL with a
function that will signal your process via some sort of IPC. When you
call SetWindowsHookEx, your DLL will be loaded into the address space
of each process you hook. You have to be very careful that your code
doesn't do anything nasty, as it will be running in every process with a
message pump on the system and could potentially bring the whole thing to
its knees.

Finally, IME some parts of the hooking API (notably the mouse hooking)
don't work as advertised. I don't recall any specific problems with the
keyboard, but keep your eyes peeled.

--
Charles Calvert | Software Design/Development
Celtic Wolf, Inc. | Project Management
http://www.celticwolf.com/ | Technical Writing
(703) 580-0210 | Research
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h01.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11936 seconds with 10 queries