Shoutbox

Edit text while typing - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Edit text while typing (/showthread.php?tid=97051)

Edit text while typing by #BG on 03-13-2011 at 06:59 PM

I'm pretty much a beginner in scripting. I'd like to make to make a script that changes one or more characters to an other one in the chat window while typing. Should I use OnEvent_ChatWndEditKeyDown to monitor every key I press? Can I use ChatWnd.EditText to delete just what I wrote, and put something else in it's place? This is what I've got so far:

code:
function OnEvent_ChatWndEditKeyDown(pChatWnd, nKeyCode, bCtrl, bShift)
{
  // Declare a variable to hold the value of the 2 virtual key
  var VK_2 = 0x32;
       
  // Check if the key pressed are Shift and 2
  if (nKeyCode == VK_2 && bShift == true)
  {
    // Validate that we can type
    if (pChatWnd.EditChangeAllowed == true)
    {
      // Gain access to the contact object
      var oContact = new Enumerator(pChatWnd.Contacts).item();

      // Validate that the contact is not blocked and that they are on the MSN network
      if (oContact.Blocked == false && oContact.Network == NETWORK_MSN)
      {
          ChatWnd.EditText = ""; // Now how should I use it?
      }
    }
  }
}

Thanks for any help!
RE: Edit text while typing by matty on 03-13-2011 at 07:14 PM

Couldn't you replace the characters in the OnEvent_ChatWndSendMessage function?


RE: Edit text while typing by #BG on 03-13-2011 at 07:45 PM

quote:
Originally posted by matty
Couldn't you replace the characters in the OnEvent_ChatWndSendMessage function?
It would be important to leave the opportunity to the user to check the auto correction, and change it back if needed. Is it more complicated this way?
RE: Edit text while typing by Matti on 03-13-2011 at 10:38 PM

It's as simple as:

js code:
ChatWnd.EditText_ReplaceSel("my replacement");
return true;
When Shift+2 is pressed, the current selection is replaced with whatever you pass to that method. When the user hasn't selected anything but is simply typing, Plus! will treat this as a selection at the current position with zero length. Therefore when you call EditText_ReplaceSel, your replacement will be inserted at the current position. After replacing the selection, simply return true to make Plus! and Messenger stop processing this key. :)
Define ChatWnd by #BG on 03-14-2011 at 01:21 AM

It's really simple then. :) However how should I define the ChatWnd object? (I still get an error and just can't figure out more from the documentations.)


RE: Edit text while typing by matty on 03-14-2011 at 02:12 AM

quote:
Originally posted by #BG
js code:


You declared the function pChatWnd so as such any references need to be pChatWnd not ChatWnd as I have highlighted in your code.