[HOWTO] -Set Key Sequence/Shortcut WINDOWS

/Hello Ruby fans/

I’m working in an small project to create a translation machine ( basically
EnglishSpanish )
I’d love to call this program with a ‘Key-Sequence shortcut’ on Window$,
I have found some ways to do it but I am wondering if there’s a ruby way to set
the shortcut .

THE IDEA IS:
1 - Ctrl-C [ love ]
2 - Key Sequence [Ctrl-Alt Z ]
3 - Ctrl-V [amor]

[snip]

class SetShortCut
# ???
end

If you create a fixed shortcut(link) to your script, e.g. to
C:\ruby\mystuff\babelfish.rb
you can add a shortcut key (Ctrl+Alt-Z) from the “Properties” page.

I’ve done it …but it does not work (weird !), currently I’m using a software
which help me to create the shortcut,
but not sure if it applies to all users in the system (I don’t think so);

I’d like to have a ruby script to create the shorcut as previous set up.

Can’t recommend, but isn’t babelfish free?

not sure if there are some hide restrictions ; )

Here is the prototype (alias : ugly code working):

···

On Fri, 21 May 2004 10:28 , ‘daz’ dooby@d10.karoo.co.uk sent: >Ronnie Bermejo wrote:

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

module BabelFish
require ‘cgi’
require ‘net/http’

    # USAGE
# input =  "ruby is like gold"
# lang   = "en_es"
# puts BabelFish.translate(lang,input)


    MAGIC_LINE=97
    RES_REGEXP=%r|<td bgcolor=white class=s><div style=padding:10px;>(.+)</div>|m


def BabelFish.translate(languages, input)
    str = CGI::escape(input)
    conn = Net::HTTP.new("babelfish.altavista.com")
    resp, data =

conn.get(“/tr?doit=done&tt=urltext&urltext=#{str}&lp=#{languages}&submit=Translate”)
lame_state_variable = false
translation = “”
#get just a chunk
data = data.split(“\n”)[MAGIC_LINE+7,MAGIC_LINE+15].to_s
data =~ RES_REGEXP
translation = $1
return translation
end

end

class Dic

def initialize(words)
   @w=words
   $words=words
end



def lookup(host,dir)
   
    h = Net::HTTP.new(host,80)
    resp, data = h.get(dir,nil )
   
       cleanhtml(data)
end

def meanning
   
    host = "dictionary.reference.com"
            dir  = "/search?q=#{$words}"
   
    cleanmeanning( lookup(host,dir) )
end

def pharse   
         host = "www.alltheweb.com"
         dir  = "/search?_oldhost=alltheweb.com&query=#{$words}"
         dir <<

“&cat=web&advanced=1&lang=english&wf%5Bn%5D=4&hits=20&nooc=off&phrase=on&submit=Search”
cleanpharse(lookup(host,dir))
end

def cleanhtml(data)
    data.gsub!(/<[^>]*>|&nbsp;|&quot;/,"")
end

def cleanpharse(data)
       res=""   
   data.split("\n").each do |line|
     if not line.empty?
       if line =~ /Advanced Search Results/
        @k=1
       end
       if line =~ /Result Page/
        @k=0
       end
       if @k == 1
        res << line          
      end
        end
   end
    res
end

def cleanmeanning(data)
    res=[]
    data.split("\n").each do |line|                                         
     if not line.empty?
       if line =~ /entries found/
        @k=1
       end
       if line =~ /SPONSORED LINKS|\[Download or Buy /
        @k=0
       end
       if @k == 1
        res <<  line.gsub(/\r/,"\n") 
      end
         end
        end
    res
end

end

class Translate
include BabelFish
require “win32/clipboard”
require “tk”

def initialize
paste(translate(copy))
end

def copy
begin
clp = Win32::Clipboard.data
return clp
rescue Exception =>e
end
end

def paste(data)
     Win32::Clipboard.data = data
end

def translate(text)        
        $text=text
        if text.split(" ").length > 1
        button="no"
    else
        button="yes"
        end       
    res = textWindow(BabelFish.translate("en_es",text),button)   
    return res
end  

def textWindow(text,button="no")
   
    @dic_text =TkRoot.new {
            title "Translator"
    }
    if   text.length.to_i   > 20
                    width=70
            else
                    width=text.length.to_i
            end           
            textW=TkText.new(@dic_text) { |t|
               background "white"
              foreground "blue"
              font "arial 9"
              wrap "word"
              relief 'sunken'
              bd 1
              setgrid 1
              width  width
             height  text.split("\n").length.to_i
            TkScrollbar.new(@dic_text) {|s|
                pack('side'=>'right', 'fill'=>'y')
                command proc{|*args| t.yview *args}
                t.yscrollcommand proc{|first,last| s.set first,last}
            }
        }.pack('expand'=>'no', 'fill'=>'both')
         if button == "yes"
            dicButton(text).pack('expand'=>'yes', 'fill'=>'both')
                 end
        n="1"   
        text.each { |line|
                textW.insert("#{n}.#{n}",line)
            n.succ!
            }
       
        Tk.mainloop  if not @ini == 1
        @ini = 1
end

def dic_lookup(text)
           textWindow(Dic.new(text).meanning.to_s)
end
def dicButton(text)
      translate = proc { dic_lookup($text) }
          @dicButton = TkButton.new (@dic_text) {
        text "Dictionary"
        height 1
        command  translate 
      }
      @dicButton
      
end      

end

#main
require ‘timeout’
timeout(30) { Translate.new }

########################
any contribution will be greatly appreciated.

begin
timeout(5days) { Worker.work }
rescue
Weekend.new
end

is friday !

-r.

---- Msg sent via Spymac Mail - http://www.spymac.com