Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Baro on Fri 04/07/2008 13:49:41

Title: Mouse implemented with numeric keyboard clicks through GUI
Post by: Baro on Fri 04/07/2008 13:49:41
I'm adding the choice of using the numeric keyboard as a mouse. 7, 8, 9, 4, 6, 1, 2 and 3 move the mouse in the 8 directions. 5 is processed as a left click and Enter as a right click.

(in the on_key_press function, which I moved after the on_mouse_clic section for token definition issues)
  if (keycode==372) mouse.SetPosition(mouse.x, mouse.y-5);   //8
  if (keycode==380) mouse.SetPosition(mouse.x, mouse.y+5);   //2
  if (keycode==375) mouse.SetPosition(mouse.x-5, mouse.y);   //4
  if (keycode==377) mouse.SetPosition(mouse.x+5, mouse.y);   //6
  if (keycode==371) mouse.SetPosition(mouse.x-5, mouse.y-5); //7
  if (keycode==373) mouse.SetPosition(mouse.x+5, mouse.y-5); //9
  if (keycode==379) mouse.SetPosition(mouse.x-5, mouse.y+5); //1
  if (keycode==381) mouse.SetPosition(mouse.x+5, mouse.y+5); //3
  if (keycode==376) on_mouse_click(eMouseLeft);              //5
  if (keycode==13)  on_mouse_click(eMouseRight);             //Enter


But when the mouse is over the GUI and I press 5 (left click), it detects it as if there were no GUI and I clicked on the background (i.e: the character walks to that spot even if mouse is over a button). When I actually click the GUI with the mouse, it processes it as a click on the GUI (nothing happens in background, buttons work, etc) since the GUI is set as clickable.
How do I make this artificial keyboard mouse actually click the GUI?

Also, I don't know if I'm going to add functionality to the mouse wheel, but if so, I'd use the - and + keys. What are their ASCII codes/where can I find a more complete list than the one in the help? (or I can only pass those in on_key_press?)
Title: Re: Mouse implemented with numeric keyboard clicks through GUI
Post by: Khris on Fri 04/07/2008 15:24:44
    int move_by=5;
  int k=keycode-371;
  if (k>=0 && k<11 && k%4!=3) {
    mouse.y-=(k/4+1)*move_by;
    mouse.x+=(k%4-1)*move_by;
  }

  if (k==5) left_click();
  ...


Afaik, on_mouse_click isn't called if the mouse is over a clickable GUI. It's not possible to invoke a left click directly, you'll have to manually check what's at the mouse's location, going through GUIs minding their z-order & clickable property. I'm not sure if there's a way to call a button's OnClick that way, let alone clicking on the scroll buttons of listboxes and stuff like that.
After the GUIs are out of the way, it's fine to call on_mouse_click.

+: 43
-: 45
Title: Re: Mouse implemented with numeric keyboard clicks through GUI
Post by: SSH on Fri 04/07/2008 16:17:37
Wouldn't it be easier to turn on Window's built-in accessibility controls that do the same thing?

Keycodes of typable characters can be easily done in script like this:


if (keycode=='+') { // do stuff }

Title: Re: Mouse implemented with numeric keyboard clicks through GUI
Post by: Dualnames on Fri 04/07/2008 16:23:02
you whatever you put as on_mouse click
if (mousebutton==left) {
}

put it as mouse click left button.
Title: Re: Mouse implemented with numeric keyboard clicks through GUI
Post by: Baro on Fri 04/07/2008 20:57:20
Quote from: KhrisMUC on Fri 04/07/2008 15:24:44
    int move_by=5;
  int k=keycode-371;
  if (k>=0 && k<11 && k%4!=3) {
    mouse.y-=(k/4+1)*move_by;
    mouse.x+=(k%4-1)*move_by;
  }

  if (k==5) left_click();
  ...


Afaik, on_mouse_click isn't called if the mouse is over a clickable GUI. It's not possible to invoke a left click directly, you'll have to manually check what's at the mouse's location, going through GUIs minding their z-order & clickable property. I'm not sure if there's a way to call a button's OnClick that way, let alone clicking on the scroll buttons of listboxes and stuff like that.
After the GUIs are out of the way, it's fine to call on_mouse_click.

+: 43
-: 45
That code doesn't work (the maths are incorrect, mouse.x and y are readonly (although I tried to create two variables and didn't work either), and left_click() doesn't exist)

Quote from: Dualnames on Fri 04/07/2008 16:23:02
you whatever you put as on_mouse click
if (mousebutton==left) {
}

put it as mouse click left button.
That's the first thing I tried, but it's a processclick, so it still goes through the GUI.

Quote from: SSH on Fri 04/07/2008 16:17:37
Wouldn't it be easier to turn on Window's built-in accessibility controls that do the same thing?

Keycodes of typable characters can be easily done in script like this:


if (keycode=='+') { // do stuff }


How do I use those controls?


Anyway, if there's no way of clicking the GUIs manually, I could add more keyboard input. For example, for the main cursors GUI, 'L' changes to look mode and so on.
Title: Re: Mouse implemented with numeric keyboard clicks through GUI
Post by: Dualnames on Fri 04/07/2008 21:01:48
Well, ok, let me be of more service to you.

Global script:
function mouse_click(Mousebutton *button) {
if (button==eMouseleft) {
ProcessClick(mouse.x,mouse.y,mouse.Mode);
}
}

//you want space to trigger left mouse click

function on_key_press(int keycode) {
if (keycode==32) {
ProcessClick(mouse.x,mouse.y,mouse.Mode);
}
}
Title: Re: Mouse implemented with numeric keyboard clicks through GUI
Post by: Baro on Fri 04/07/2008 21:06:53
Quote from: Dualnames on Fri 04/07/2008 21:01:48
Well, ok, let me be of more service to you.

Global script:
function mouse_click(Mousebutton *button) {
if (button==eMouseleft) {
ProcessClick(mouse.x,mouse.y,mouse.Mode);
}
}

//you want space to trigger left mouse click

function on_key_press(int keycode) {
if (keycode==32) {
ProcessClick(mouse.x,mouse.y,mouse.Mode);
}
}

Quote from: HELP FILEProcessClick
NOTE: This function ignores all interfaces and acts as though the point is directly visible. In other words, if the co-ordinates you pass happen to lie on a button on an interface, what actually happens will be as if the user clicked behind the interface onto the actual screen.

That's the problem, that what I wanted to do is actually click the GUI and notwhatever it's behind it.
However, I don't understand why it does click the GUIs when it actually loads on_mouse_click or processclick from an actual click from the actual mouse (although that's what it is supposed to do). That'd be the key to do this.