mIRC Homepage
Posted By: dr_Eamer Multiple spaces in on input event. - 22/08/04 12:34 PM
A vary simple and naive on input remote that simply msgs the input to the channel:
Code:
on *:INPUT:#:{ msg $chan $1- } 

The problem with this code is that it can't handle multiple spaces because tokenization with $1- eats them up.
In on text events with incoming text this can be solved with $rawtext which contains the ACTUAL text.
What can be done in an on input event? $editbox returns $null (the editbox is cleared before the remote is triggered). How can I get the ORIGINAL input text with the multiple spaces and all?

This is a problem in theme engines, nick completers and so many common addons that handle input text. Isn't there a way around it?

I hope this hasn't been discussed earlier... My search gave no such previous discussions...
There's no decent solution for it. The only practical way that this will ever work is if Khaled adds $rawmsg to the input event.

Here's a scripted 'solution', although I have no clue just how well it works on other systems (it's possible the key sending stuff might not register in time for the timer on some computers).

Code:
on *:input:*:{
  sendkeys {UP}
  .timer -m 1 0 var $+(%,r) $(|) !.echo -q $!regsub($editbox( $target ),/(\x20(?=\x20))/g,$+($chr(32),),%r) $(|) .signal rawinput $replace($target,$chr(32),$cr) $ctrlenter $+(%,r) $(|) sendkeys {DOWN}
}

on *:signal:rawinput:{
  [color:blue]; $replace($1,$cr,$chr(32) contains ON INPUT's $target value[/color]
  [color:blue]; $2 contains ON INPUT's $ctrlenter value[/color]
  [color:blue]; $3- will contain ON INPUT's $1- value but will retain spaces (they've been padded with control codes)[/color]
  [color:red]; YOUR CODE HERE[/color]
}

alias sendkeys {
  var %obj = $+(sk, $ticks)
  .comopen %obj WScript.Shell
  .comclose %obj $com(%obj, SendKeys, 3, *bstr, $1-)
}


Just use the RAWINPUT signal event instead of on INPUT for your code.
Posted By: dr_Eamer Re: Multiple spaces in on input event. - 22/08/04 04:09 PM
In general I think the thing with spaces is quite a serious problem!
regsubing spaces with ctrl-b's even in on text events can make the text too big! Simply using $1- is not acceptable in aligned text (ascii art, server stats etc).
Not many people seem concerned about it though it seems...

Using $rawmsg in outgoiing events would be nice.

Posted By: myndzi Re: Multiple spaces in on input event. - 24/08/04 09:24 PM
I wrote a couple signal events that allowed me to trigger scripts when the text in the active editbox changed or was cleared. Something similar could be applied here:

Code:
on *:start:if ($timer(irt) == $null) irt_chk
on *:input:*:if ($timer(irt) == $null) irt_chk
on *:close:*:var %w = $window($target).wid | if ($hget(irt, %w)) hdel irt %w

alias input_rawtext return $hget(irt, $window($active).wid)
alias irt_chk {
  .timerirt -oim 1 10 if ($isalias(irt_chk)) irt_chk
  var %e = $replace($editbox($active), $chr(32), $chr(0160)), %w = $window($active).wid
  if (%e != $hget(irt, %w)) {
    if (%e == $null) hdel irt %w
    else hadd -m irt %w %e
  }
}
 


It should be noted that when I am placeholding spaces I usually use $lf since it can't normally be provided in the input text (while chr(0160) can) but I didn't do that here for clarity's sake.

As you can see, all this does is keep a hash table updated with the text that's in each window; the table entry is deleted when the editbox clears, but the on input event triggers before it can do so. Therefore, if you call $input_rawtext inside an on input event, you will get the text they typed in the editbox.

-myndzi
© mIRC Discussion Forums