Page 1 of 1

keyboardType() - using symbols and stuff.

Posted: Thu Jun 26, 2008 11:56 pm
by zer0
Hey, I'm using MicroMacro in Shaiya.

I'm trying to get it to run macro's in the message window with keyboardType() function:

an example:

Code: Select all

  keyboardPress(key.VK_ENTER);
  keyboardType("/partyinvite _someuser_");
  keyboardPress(key.VK_ENTER);
The issue is that slashes "/", and "_" are not being entered. I took a look at micromacro's source, but I have no idea how to setup the project (I use CodeBlocks), and in the:

macro.cpp
void macro::keyboardType(std::string message)

There is some pretty low level coding going on which I don't really understand.

Re: keyboardType() - using symbols and stuff.

Posted: Fri Jun 27, 2008 1:23 am
by Administrator
Yeah, keyboardType() still needs to be fixed. The problem with it is that I can either make special cases for all symbols (which would probably break under different keyboard layouts), or need to rewrite the whole function. Actually, I'll work on that now.

Re: keyboardType() - using symbols and stuff.

Posted: Fri Jun 27, 2008 1:46 am
by zer0
That would be fantastic. :D

I tried compiling in CodeBlocks but I'm missing a bunch of libraries, and I can't b bothered figuring it out cause it takes a long time. To configure a development environment. Plus I'd be next to useless, cause at a quick glance I didn't understand ur code. ;)

Re: keyboardType() - using symbols and stuff.

Posted: Fri Jun 27, 2008 2:41 am
by Administrator
Not surprising. Sometimes, I don't even understand my code. But all joking aside, I do find it is harder to make sense of somebody elses code most of the time. And keyboardType() was a mess. Here's the new, revised keyboardType() that should work most of the time (although is kind of hackish).

Code: Select all

/*  Function: keyboardType
    Description:
      Types the string passed to it, as if typed by the user.
*/
void macro::keyboardType(std::string message)
{
// http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx

  for(unsigned int i = 0; i < message.length(); i++)
  {
    char thischar = message.at(i);
    if( thischar == '\n' ) {
      keyPress(VK_RETURN);
      continue; }

    char vk = VkKeyScan(thischar);
    char keyscan = MapVirtualKey(vk, 0);

    int capitol = ( thischar >= 'A' && thischar <= 'Z' );
    int needshift = (thischar >= '!' && thischar <= '&') ||
      (thischar >= '(' && thischar <= '+') ||
      (thischar == ':') || (thischar == '<') || (thischar == '>') ||
      (thischar == '?') || (thischar == '@') || (thischar == '^') ||
      (thischar == '_') || (thischar >= '{' && thischar <= '~');


    if( capitol || needshift )
      keyHold(VK_SHIFT);

    keybd_event(vk, keyscan, 0, 0);
    rest(keyboardDelay);
    keybd_event(vk, keyscan, KEYEVENTF_KEYUP, 0);
    rest(keyboardDelay);

    if( capitol || needshift )
      keyRelease(VK_SHIFT);
  }
}
I've just uploaded the fixed version to the server, so you can fetch it off the download page.

Re: keyboardType() - using symbols and stuff.

Posted: Fri Jun 27, 2008 3:18 am
by zer0
thanks allot. :D

I wasn't referring to ur coding style, just that I don't understand bitwise comparison/operators well. I'll test it now.