SRL Archive - RS3 Help

ALT+TAB and SMART


fady

2015-03-02 23:44:33

When I ALT+TAB out of SMART, the keyboard stops working. Even if I ALT+TAB back in, the keyboard will only resume functionality when i press on ALT inside smart. Is this only me? or is it a common thing? also is there a way around it?

notadad

2015-03-03 00:14:25

It might be only you, I haven't had a problem like that. Very strange issue, have you tried going through the installation process again?

Turpinator

2015-03-03 00:36:37

alt + tab is how smart 8.0 and lower used to grab focus of the client or something to that effect.
just make sure you have 8.3 and this shouldnt be an issue.

Olly

2015-03-03 01:19:16

From: Turpinator
alt + tab is how smart 8.0 and lower used to grab focus of the client or something to that effect.
just make sure you have 8.3 and this shouldnt be an issue.


iirc it's the other way around? I think it used to type a key (and rs interptered it as `) or something before?

I think now it alt+tabs.

edit:
https://github.com/BenLand100/SMART/blob/6f5468c817d255584d3f6cf6823a4a1fe5494888/src/EventNazi.java#L580

Seems so.

Turpinator

2015-03-03 01:29:14

From: Olly
iirc it's the other way around? I think it used to type a key (and rs interptered it as `) or something before?

I think now it alt+tabs.

edit:
https://github.com/BenLand100/SMART/blob/6f5468c817d255584d3f6cf6823a4a1fe5494888/src/EventNazi.java#L580

Seems so.


Oh. yeah, sure. Ive never experienced this issue though. anyone else?

fady

2015-03-03 08:19:17

From: Turpinator
alt + tab is how smart 8.0 and lower used to grab focus of the client or something to that effect.
just make sure you have 8.3 and this shouldnt be an issue.


From: Olly
iirc it's the other way around? I think it used to type a key (and rs interptered it as `) or something before?

I think now it alt+tabs.

edit:
https://github.com/BenLand100/SMART/blob/6f5468c817d255584d3f6cf6823a4a1fe5494888/src/EventNazi.java#L580

Seems so.



sorry, I'm still confused lol. I dont think I was specific engough! It was late and I was sleepy, so I apologize. To be more specific. If I hold ALT while smart is my main window, keyboard clicks won't send to the game! So if I hold ALT and press 1, B, H, my action bar wont click, my backpack and my skills tab wont open, respectively. However!!!! and here's the strange part to me. If I press ENTER while holding ALT, the chat box will become active, and if I press 1, B, H after I press ENTER, while still while holding down ALT, the chat box will detect these clicks and type them! but the game wont detect them when the chat box isn't active.

So, all the things that I have described above will happen when I use both SMART, and the regular runescape client. However, only SMART will get stuck in that "mode" when I ALT+TAB to other windows. How do i know that only SMART gets stuck you ask? because when i switch back to both clients after ALT+TAB-ing out, the runescape client will function normally, but SMART will still be stuck in that "mode" until I press on ALT again, which seems to fix it. So, I think that the problem is that SMART will think that I am still holding down ALT when I ALT+TAB out of it.

Is this only me? Is there anyway to fix it? what could be causing this problem?

Brandon

2015-03-03 08:56:36

From: fady
sorry, I'm still confused lol. I dont think I was specific engough! It was late and I was sleepy, so I apologize. To be more specific. If I hold ALT while smart is my main window, keyboard clicks won't send to the game! So if I hold ALT and press 1, B, H, my action bar wont click, my backpack and my skills tab wont open, respectively. However!!!! and here's the strange part to me. If I press ENTER while holding ALT, the chat box will become active, and if I press 1, B, H after I press ENTER, while still while holding down ALT, the chat box will detect these clicks and type them! but the game wont detect them when the chat box isn't active.

So, all the things that I have described above will happen when I use both SMART, and the regular runescape client. However, only SMART will get stuck in that "mode" when I ALT+TAB to other windows. How do i know that only SMART gets stuck you ask? because when i switch back to both clients after ALT+TAB-ing out, the runescape client will function normally, but SMART will still be stuck in that "mode" until I press on ALT again, which seems to fix it. So, I think that the problem is that SMART will think that I am still holding down ALT when I ALT+TAB out of it.

Is this only me? Is there anyway to fix it? what could be causing this problem?



Turpinator was right the first time. SMART doesn't use Alt-Tab to gain focus anymore. You can see this in EventNazi.java. It only sends FocusGained and FocusLost events. You can check by doing CTRL + F and typing: "loseFocus(true)". When the parameter is true, it will alt-tab out (which it doesn't due to the parameter always being false). Ben also uses client.setFocusTraversalKeysEnabled(false) so that the frame doesn't capture the alt-keys to traverse its components/buttons.


Now for the real issue. The keys are added to a QUEUE when you press them. If you say that the window is switched before you get a chance to release the key, then SMART still thinks that key is being held even though you may have released it when another window has focus. SMART's key held flags are still there. When you go back to SMART and it now has focus and you press the key that was NOT released when it lost focus, the key is removed from the flags and everything is back to normal.


I'd say you have an OS problem. SMART is not supposed to lose focus when you press ALT + TAB (down) + Tab(up). You can try this with any window. It does NOT switch windows until you release ALT.. aka "Alt(down)+ Tab(down); Tab(up) + Alt(up).. That's why your problem is so hard to figure out. I know what it's doing and where it's caused, but cannot replicate it.


It should also remove it from the keys held flags after a certain amount of time: https://github.com/BenLand100/SMART/blob/master/src/EventNazi.java#L731


Besides, any events on the client itself by a human (not Simba or computer program), is sent as an UnblockedEvent and should not even go through the keys held thread so your problem is more difficult to pin-point.

fady

2015-03-03 10:59:17

From: Brandon
Turpinator was right the first time. SMART doesn't use Alt-Tab to gain focus anymore. You can see this in EventNazi.java. It only sends FocusGained and FocusLost events. You can check by doing CTRL + F and typing: "loseFocus(true)". When the parameter is true, it will alt-tab out (which it doesn't due to the parameter always being false). Ben also uses client.setFocusTraversalKeysEnabled(false) so that the frame doesn't capture the alt-keys to traverse its components/buttons.


Now for the real issue. The keys are added to a QUEUE when you press them. If you say that the window is switched before you get a chance to release the key, then SMART still thinks that key is being held even though you may have released it when another window has focus. SMART's key held flags are still there. When you go back to SMART and it now has focus and you press the key that was NOT released when it lost focus, the key is removed from the flags and everything is back to normal.


I'd say you have an OS problem. SMART is not supposed to lose focus when you press ALT + TAB (down) + Tab(up). You can try this with any window. It does NOT switch windows until you release ALT.. aka "Alt(down)+ Tab(down); Tab(up) + Alt(up).. That's why your problem is so hard to figure out. I know what it's doing and where it's caused, but cannot replicate it.


It should also remove it from the keys held flags after a certain amount of time: https://github.com/BenLand100/SMART/blob/master/src/EventNazi.java#L731


Besides, any events on the client itself by a human (not Simba or computer program), is sent as an UnblockedEvent and should not even go through the keys held thread so your problem is more difficult to pin-point.


I have windows 8.1, and it is "Alt(down)+ Tab(down); Tab(up) + Alt(up)" sorry. However before Alt(up) it shows me a preview of the other screen I'm going to, could that be why SMART isnt detecting the Alt(up) part? because I usually bot while I do other things on my laptop, and I constantly check up on the bot to see that its working. Alt+Tab-ing in and out usually messes up any bot that will use keyboard clicks for me.

I've been doing more testing on this trying to figure out what the problem is, and this is what I've come up with. The problem is different depending on whether or not SMART is enabled/disabled

If SMART is Enabled, and I Alt+Tab out of the window, when I go back into the window(didn't matter how I did it) an ALT click will make the mouse change to the regular mouse image, and not the runescape mouse image.

If I click a button on the keyboard at that moment, I will hear a windows error sound, and the mouse image will return to the runscape image and the keyboard would be functional again.
However, If I press ALT again after the first time, the mouse image will return to the runescape image and the keyboard will be functional without the annoying error sound.

However, if SMART is disabled, the same thing will happen as above, except the keyboard wont become functional again at the end. Only a mouse click inside the SMART window will make it functional again.

I have a feeling this has something to do with the fact that in other windows an ALT press will open the menu bar, but SMART doesn't have a menu bar! I have no idea how to fix it in SMART, or how to stop it from happening in windows as a whole.

any advice would be much appreciated. I apologize again if i wasn't too specific with all my previous posts. I never thought I'd be the only one with this issue, so I didn't think I'd have to do too much explaining/experimenting.

Turpinator

2015-03-03 11:59:21

From: fady
I have windows 8.1, and it is "Alt(down)+ Tab(down); Tab(up) + Alt(up)" sorry. However before Alt(up) it shows me a preview of the other screen I'm going to, could that be why SMART isnt detecting the Alt(up) part? because I usually bot while I do other things on my laptop, and I constantly check up on the bot to see that its working. Alt+Tab-ing in and out usually messes up any bot that will use keyboard clicks for me.

I've been doing more testing on this trying to figure out what the problem is, and this is what I've come up with. The problem is different depending on whether or not SMART is enabled/disabled

If SMART is Enabled, and I Alt+Tab out of the window, when I go back into the window(didn't matter how I did it) an ALT click will make the mouse change to the regular mouse image, and not the runescape mouse image.

If I click a button on the keyboard at that moment, I will hear a windows error sound, and the mouse image will return to the runscape image and the keyboard would be functional again.
However, If I press ALT again after the first time, the mouse image will return to the runescape image and the keyboard will be functional without the annoying error sound.

However, if SMART is disabled, the same thing will happen as above, except the keyboard wont become functional again at the end. Only a mouse click inside the SMART window will make it functional again.

I have a feeling this has something to do with the fact that in other windows an ALT press will open the menu bar, but SMART doesn't have a menu bar! I have no idea how to fix it in SMART, or how to stop it from happening in windows as a whole.

any advice would be much appreciated. I apologize again if i wasn't too specific with all my previous posts. I never thought I'd be the only one with this issue, so I didn't think I'd have to do too much explaining/experimenting.


Ill start with each statement/comment.
1) alt-tab aero peek is on windows 7 also. (it might be called something different on 8)
2)
3) you should have custom cursors disabled. (it shouldnt make a difference, but just try turning them off)
.
.
.
yup.

Brandon

2015-03-03 12:32:34

The problem is actually the system menu (and there's no way to get rid of it in Java)..

Was able to replicate the problem:

When I Disable SMART allowing mouse input and all input through, if I alt-tab away, and alt-tab + an extra alt to disable the custom cursor back (with custom cursor on and hovering over a banker for visualisation), you can see the custom cursor over the bank, but the real cursor is actually else where. You are free to move the real cursor around while the RS cursor is still at the banker because the Canvas doesn't have focus (the JFrame does due to the alt-system-menu)..

That is because the alt key brought up the system menu HOTKEY. The only way to disable this via pure Java is to disable the alt-key entirely and that means you won't be able to use any in game alt key bindings.

The other option is to stop SMART's manual tracking of focus and instead have it "ask" the component if it has focus and request focus that way. The problem is:


public synchronized void passKeyEvent(KeyEvent e) {
if (canInteract()) {
if (!focused) getFocus(); ///THIS LINE IS THE PROBLEM..
//System.out.println("Passing Event: " + e.getKeyChar());
BlockingEventQueue.sendUnblocked(new KeyEvent(comp, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation()));
}
}


"focused" is a boolean inside the class containing the above code. This boolean isn't updated when the user alt-tab's away. SMART thinks it still has focus but it doesn't.. We either update that boolean on focusLost event OR we call component.isFocusOwner() or KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == component to check if the canvas has focus or not and regain it..


That's a decent solution.. BUT it doesn't fix the mouse image problem..


The last option is to use JNI (SmartJNI.cpp) and reflection (to get the window handle on Windows) and call the native WINAPI function:



Object peer = invokeMethod(clientFrame, "getPeer");
Long hwnd = (Long)invokeMethod(peer, "getHWnd");


SetWindowLongPtr(hwnd, GetWindowLongPtr(hwnd, GWL_STYLE) &~ WS_SYSMENU);

//or

HMENU mnu = GetSystemMenu(hwnd, false);
for (int i = 0; i < GetMenuCount(mnu); ++i)
DeleteMenu(mnu, SC_MOVE, MF_BYCOMMAND);


Personally, the JNI is the best option because it just removes the problem entirely without worrying about focus managing and all that non-sense. Although, I did notice that typing through SMART is MUCH MUCH easier when you fix the focus stuff.

Up to you guys. Just recompile SMART and you're good to go. Someone patch it.

fady

2015-03-03 13:31:06

From: Brandon
The problem is actually the system menu (and there's no way to get rid of it in Java)..

Was able to replicate the problem:

When I Disable SMART allowing mouse input and all input through, if I alt-tab away, and alt-tab + an extra alt to disable the custom cursor back (with custom cursor on and hovering over a banker for visualisation), you can see the custom cursor over the bank, but the real cursor is actually else where. You are free to move the real cursor around while the RS cursor is still at the banker because the Canvas doesn't have focus (the JFrame does due to the alt-system-menu)..

That is because the alt key brought up the system menu HOTKEY. The only way to disable this via pure Java is to disable the alt-key entirely and that means you won't be able to use any in game alt key bindings.

The other option is to stop SMART's manual tracking of focus and instead have it "ask" the component if it has focus and request focus that way. The problem is:


public synchronized void passKeyEvent(KeyEvent e) {
if (canInteract()) {
if (!focused) getFocus(); ///THIS LINE IS THE PROBLEM..
//System.out.println("Passing Event: " + e.getKeyChar());
BlockingEventQueue.sendUnblocked(new KeyEvent(comp, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation()));
}
}


"focused" is a boolean inside the class containing the above code. This boolean isn't updated when the user alt-tab's away. SMART thinks it still has focus but it doesn't.. We either update that boolean on focusLost event OR we call component.isFocusOwner() or KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == component to check if the canvas has focus or not and regain it..


That's a decent solution.. BUT it doesn't fix the mouse image problem..


The last option is to use JNI (SmartJNI.cpp) and reflection (to get the window handle on Windows) and call the native WINAPI function:



Object peer = invokeMethod(clientFrame, "getPeer");
Long hwnd = (Long)invokeMethod(peer, "getHWnd");


SetWindowLongPtr(hwnd, GetWindowLongPtr(hwnd, GWL_STYLE) &~ WS_SYSMENU);

//or

HMENU mnu = GetSystemMenu(hwnd, false);
for (int i = 0; i < GetMenuCount(mnu); ++i)
DeleteMenu(mnu, SC_MOVE, MF_BYCOMMAND);


Personally, the JNI is the best option because it just removes the problem entirely without worrying about focus managing and all that non-sense. Although, I did notice that typing through SMART is MUCH MUCH easier when you fix the focus stuff.

Up to you guys. Just recompile SMART and you're good to go. Someone patch it.


I'm sorry, I don't mean to be disrespectful, but I have almost no idea what most of that code means. From what I could gather tho, is that the problem isn't specific to me, but in fact a windows/java problem, and that I personally can't do anything about it. Did I get that correctly?

also how do I recompile SMART?

I guess the only thing I personally can do is avoid using Alt+Tab in/out of SMART when botting

Brandon

2015-03-03 15:42:42

From: fady
I'm sorry, I don't mean to be disrespectful, but I have almost no idea what most of that code means. From what I could gather tho, is that the problem isn't specific to me, but in fact a windows/java problem, and that I personally can't do anything about it. Did I get that correctly?

also how do I recompile SMART?

I guess the only thing I personally can do is avoid using Alt+Tab in/out of SMART when botting



Here.. Try these: [ATTACH=CONFIG]25181[/ATTACH] Should have none of the problems described. You'll still be able to do Alt-Tab and Alt-AnyCombo. I've tested this both in and out of RS. You can use Alt+Whatever you want to still bring up in game interfaces and Alt-Tab to switch to another window and back without problems. Your cursor will not longer have the image glitch.


CHANGE-LOG:

I've incorporated the patch for: https://github.com/BenLand100/SMART/issues/23

as well as all of the below to patch the Alt-System-Menu.

SmartJNI.cpp:

#ifdef _WIN32
WNDPROC original_proc = NULL; //Original JVM WindowProcedure (for the JFRAME, not the applet or canvas). Nothing to do with RS.

//New WindowProcedure removing that ignores the Alt-System Menu Key.
LRESULT __stdcall AltMenuHook(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_SYSCOMMAND:
{
if (wParam == SC_KEYMENU && ((lParam >> 16) <= 0)) //If it is the SystemMenu AND *ALT OR ALT + SomeKey*, ignore it.
{
return 0; //Make it so that the key(s) was never pressed.
}
}
break;
}
return CallWindowProc(original_proc, hwnd, uMsg, wParam, lParam); //Allow the JVM to handle all other stuff.
}
#endif

//Subclasses the JVM's WindowProcedure allowing us to modify it to remove the ALT-System-Menu.
extern "C" JNIEXPORT void JNICALL Java_smart_Main_disableAltMenu(JNIEnv *env, jclass cls, jlong jhwnd) {
#ifdef _WIN32
if (jhwnd == -1) {
return;
}

HWND hwnd = (HWND)jhwnd;
/*LONG_PTR style = GetWindowLongPtr(hwnd, GWL_STYLE);
style &= ~(WS_SYSMENU);
SetWindowLongPtr(hwnd, GWL_STYLE, style);
SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);*/

original_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)AltMenuHook);
#endif
}


Client.Java:

private void initFrame() {
//All other code here..


//At the end of the method when all buttons are finished being added to SMART, we make them not focusable.
//Also disable traversal via the tab key. Thus, the buttons/components should never have focus.. Ever.
for (Component c : south.getComponents()) { //only disable focusable in the south panel (button panel).
c.setFocusTraversalKeysEnabled(false);
c.setFocusable(false);
}
}

//To be used in the main class to pass to the JNI functions.. Can easily alternatively move the code in the main class to this method instead.
public JFrame getMainWindow() {
return this.clientFrame;
}


Main.Java:

import java.lang.reflect.InvocationTargetException; //for reflection.
import java.lang.reflect.Method; //for reflection.


/**
* Patch for System Menu on Alt.
*/
public static native void disableAltMenu(long hwnd);


/**
* Patch for System Menu on Alt. Retrieves the native handle of the main frame via Reflection so as to not affect Linux users.
*/
public static long getWindowHandle(javax.swing.JFrame f) {
try {
Method getPeer = f.getClass().getMethod("getPeer");
Object peer = getPeer.invoke(f);
Method getHwnd = peer.getClass().getMethod("getHWnd");
return (Long) getHwnd.invoke(peer);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
return -1; //return System Message Only Window as specified by WinAPI. You should NOT perform operations on this!
}

public static void main(String[] args) {
//All other code here..

setNatives(.....);

//I added the below right after "setNatives".
disableAltMenu(getWindowHandle(client.getMainWindow())); //PATCH TO DISABLE ALT-MENU.

//All other code here..
}

libsmartjni.def:

EXPORTS
Java_smart_Main_disableAltMenu=Java_smart_Main_disableAltMenu@16 ;To patch the Alt-System-Menu.
Java_smart_Main_checkAlive=Java_smart_Main_checkAlive@12
Java_smart_Main_getPID=Java_smart_Main_getPID@8
Java_smart_Main_getGlobalRef=Java_smart_Main_getGlobalRef@12
Java_smart_Main_putGlobalRef=Java_smart_Main_putGlobalRef@16
Java_smart_Main_freeGlobalRef=Java_smart_Main_freeGlobalRef@12
Java_smart_Main_pathFromAddress=Java_smart_Main_pathFromAddress@12
Java_smart_Main_indexFromAddress=Java_smart_Main_indexFromAddress@16
Java_smart_Main_setupPlugins=Java_smart_Main_setupPlugins@12
Java_smart_Main_loadPlugin=Java_smart_Main_loadPlugin@12
Java_smart_Main_setNatives=Java_smart_Main_setNatives@28
Java_smart_Main_initPlugin=Java_smart_Main_initPlugin@12
Java_smart_Main_nativeButton=Java_smart_Main_nativeButton@20
getMousePos
setCapture

fady

2015-03-03 16:16:31

From: Brandon
Here.. Try these: [ATTACH=CONFIG]25181[/ATTACH] Should have none of the problems described. You'll still be able to do Alt-Tab and Alt-AnyCombo. I've tested this both in and out of RS. You can use Alt+Whatever you want to still bring up in game interfaces and Alt-Tab to switch to another window and back without problems. Your cursor will not longer have the image glitch.


I'm sorry for asking what might be a very stupid question! but I should unzip this in "Simba/Plugins/" and override my current files correct?

also, Thank you very much for taking the time to make a fix for this.

Brandon

2015-03-03 16:31:01

From: fady
I'm sorry for asking what might be a very stupid question! but I should unzip this in "Simba/Plugins/" and override my current files correct?

also, Thank you very much for taking the time to make a fix for this.


Make a backup first then replace it yes.

fady

2015-03-03 17:17:28

From: Brandon
Make a backup first then replace it yes.


Thank you for clearing that up and for taking the time to help me! I made a backup and I replaced them, and The mouse image no longer changes, and the windows sound no longer happens. However, when i Alt+Tab out of smart, and then switch back, the keyboard still loses functionality(except pressing enter and typing in the chat box)

with smart enabled I still need to press ALT to make it work. However, I only need to click once now, because I'm assuming it is no longer going to the system menu.

with SMART disabled, I still need to click with my mouse inside the SMART window to make the keyboard work again, and ALT doesn't change the mouse or make a windows sound.

In all cases, the keyboard works within the chat box (enter button + typing), but not to open tabs or menus or click the action bar. unless I press ALT when SMART is Enabled, or click the mouse inside the window when SMART is Disabled.

I really appreciate your help.

Brandon

2015-03-03 17:38:31

From: fady
Thank you for clearing that up and for taking the time to help me! I made a backup and I replaced them, and The mouse image no longer changes, and the windows sound no longer happens. However, when i Alt+Tab out of smart, and then switch back, the keyboard still loses functionality(except pressing enter and typing in the chat box)

with smart enabled I still need to press ALT to make it work. However, I only need to click once now, because I'm assuming it is no longer going to the system menu.

with SMART disabled, I still need to click with my mouse inside the SMART window to make the keyboard work again, and ALT doesn't change the mouse or make a windows sound.

In all cases, the keyboard works within the chat box (enter button + typing), but not to open tabs or menus or click the action bar. unless I press ALT when SMART is Enabled, or click the mouse inside the window when SMART is Disabled.

I really appreciate your help.



I did not force the canvas to request focus. You always needed to click inside the frame for it to allow you to type. The only thing I changed was the Alt-Menu which messed up quite a lot. Is there a reason you don't want to click before typing? With SMART Disabled all input goes through.

I guess I can patch that but I'm not sure if it is really necessary. I'll see what I can do.


EDIT: @fady;

Try this: [ATTACH=CONFIG]25184[/ATTACH]


CHANGE-LOG v2:

Client.Java:

void setFocusCanvas() {
Component canvas = clientApplet.getComponent(0);
if (!canvas.isFocusOwner()) {
canvas.requestFocusInWindow();
}
}


/**
* Handles all button presses on the GUI
*/
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == blockingbtn) {
blockingbtn.setEnabled(false);
if (blocking) {
stopBlocking();
setFocusCanvas(); //added..
} else {
startBlocking();
}
}
}

//Added to initFrame:
clientFrame.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
if (nazi != null) {
nazi.passKeyEvent(e);
} else {
setFocusCanvas(); //added..
canvas.dispatchEvent(e); //added..
}
}
@Override
public void keyPressed(KeyEvent e) {
if (nazi != null) {
nazi.passKeyEvent(e);
} else {
setFocusCanvas(); //added..
canvas.dispatchEvent(e); //added..
}
}
@Override
public void keyReleased(KeyEvent e) {
if (nazi != null) {
nazi.passKeyEvent(e);
} else {
setFocusCanvas(); //added..
canvas.dispatchEvent(e); //added..
}
}
});

If the canvas doesn't have focus when you try to type something, it requests focus but only if blocking is disabled (which is when the bug happens).. The above should allow you to alt-tab away just fine and regain focus as soon as you attempt to type. Clicking already regains focus on its own so there's no need for any changes.

SMART's EventQueue already handles focus and events when blocking is enabled.

fady

2015-03-03 18:38:08

From: Brandon
I did not force the canvas to request focus. You always needed to click inside the frame for it to allow you to type. The only thing I changed was the Alt-Menu which messed up quite a lot. Is there a reason you don't want to click before typing? With SMART Disabled all input goes through.

I guess I can patch that but I'm not sure if it is really necessary.


My main concern is that when I have a script running that will use the keyboard to either click the action bar or perform other functions, Alt+tab-ing out of SMART is going to stop that script from running, because the keyboard clicks won't go through. I usually bot while baby sitting the script, and I continually Alt+tab in and out of SMART to check on it.

I mentioned the SMART disabled portion because I thought maybe it would be useful info (and I wanted to be thorough and not miss anything) because it acts differently, where pressing ALT again while SMART is enabled will return function to keyboard presses through SMART, but pressing ALT doesn't fix the issue when SMART is disabled. Sorry if that was irrelevant information.

With Smart Enabled:
If I Alt+Tab out of Smart then click back in or Alt+Tab back in, the keyboard presses from my scripts will stop functioning (except the enter key, and whatever is typed in the RS chat box) so for example:
if I have a script:
typeSend('1', false);

to click the action bar. Slot 1 won't be activated.

However, If I have the script type "1" in the chat box like so:
TypeByte(VK_ENTER);
typeSend('1');

The "1" will be typed in the chat box.

Thirdly If i have a script doing both, typing 1 in the Chat box and sending first, then pressing 1 for the action bar like so:
  TypeByte(VK_ENTER);
typeSend('1');
typeSend('1', false);

The first "1" will be typed, but the second "1" will not activate slot 1 in the Action bar


Now, If I Alt+Tab out of SMART, then come back which ever way I choose, then press Alt once, on the keyboard. The scripts from the previous example will all yield the results they are supposed to.

All of the previous was done with SMART enabled, which is what I care about.


I have also noticed that holding down ALT (without Alt+Tab-ing out of SMART) while running the scripts will yield the same results as the first set of attempts.

Is there any solution to that problem? Is this only happening to me?

If there Isn't a fix I'll just try to avoid using Alt Tab while botting. Thank you for all your help, I really appreciate it!

Brandon

2015-03-03 18:50:59

From: fady
My main concern is that when I have a script running that will use the keyboard to either click the action bar or perform other functions, Alt+tab-ing out of SMART is going to stop that script from running, because the keyboard clicks won't go through. I usually bot while baby sitting the script, and I continually Alt+tab in and out of SMART to check on it.


To be blunt, you should not be expecting the script to type in SMART while it is disabled. Scripts are only supposed to function when SMART is enabled (blocking mouse input). That's the only type a script should be able to send commands through to SMART (although, it still sends commands even if disabled).

Try the latest patch. It will request focus when you disable SMART if the canvas doesn't have focus. It will also request focus when you attempt to type if the canvas doesn't have focus. You should have no problems now (hopefully).

Typing should be noticeably easier and smoother.

fady

2015-03-03 18:57:42

From: Brandon
Try the patch in the last post right before yours. To be blunt, you should not be expecting the script to type in SMART while it is disabled. Scripts are only supposed to function when SMART is enabled (blocking mouse input). That's the only type a script should be able to send commands through to SMART.

However, I did patch it so that the script can type when alt-tabbed back and forth. Let me know if that fixes the problem.. Otherwise I have no idea what you mean.


I know that. My problem however, happens when SMART IS enabled, well it happens in both, but I only care about when SMART is enabled. I only mentioned the part where it happens when SMART is disabled, because I thought it might be relavent, and help you diagnose the problem, I apologize for the confusion (English isn't my first language, and I sometimes get confused).


I'll give the patch a try and give you an update if it fixed the problem.

I'll try it once it is back up.

trying it now

Thank you for taking the time to try and solve my problem!


EDIT:
From: Brandon
Try the patch in the last post right before yours



I tried the fix, and it has not solved my problem which I wanted to fix from 2 posts ago.

From: fady
With Smart Enabled:
If I Alt+Tab out of Smart then click back in or Alt+Tab back in, the keyboard presses from my scripts will stop functioning (except the enter key, and whatever is typed in the RS chat box) so for example:
if I have a script:
typeSend('1', false);

to click the action bar. Slot 1 won't be activated.

However, If I have the script type "1" in the chat box like so:
TypeByte(VK_ENTER);
typeSend('1');

The "1" will be typed in the chat box.

Thirdly If i have a script doing both, typing 1 in the Chat box and sending first, then pressing 1 for the action bar like so:
  TypeByte(VK_ENTER);
typeSend('1');
typeSend('1', false);

The first "1" will be typed, but the second "1" will not activate slot 1 in the Action bar


Now, If I Alt+Tab out of SMART, then come back which ever way I choose, then press Alt once, on the keyboard. The scripts from the previous example will all yield the results they are supposed to.

All of the previous was done with SMART enabled, which is what I care about.


I have also noticed that holding down ALT (without Alt+Tab-ing out of SMART) while running the scripts will yield the same results as the first set of attempts.

Is there any solution to that problem? Is this only happening to me?

If there Isn't a fix I'll just try to avoid using Alt Tab while botting. Thank you for all your help, I really appreciate it!




EDIT #2

I won't be online for a couple of hours, so I apologize if I'm late with my replies.
nvm I'm here

Brandon

2015-03-03 20:56:18

From: fady
I know that. My problem however, happens when SMART IS enabled, well it happens in both, but I only care about when SMART is enabled. I only mentioned the part where it happens when SMART is disabled, because I thought it might be relavent, and help you diagnose the problem, I apologize for the confusion (English isn't my first language, and I sometimes get confused).



Well I'll be damned if you're not right.. I was about to give up and think that you're just crazy.. But then I logged into RS and tried to run the following script AFTER Alt-Tabbing from SMART to the Simba window:


{$DEFINE SMART}
{$I SRL-6/SRL.Simba}

begin
SetupSRL;
TypeByte(VK_ENTER); //enter to activate chat.
typeSend('1'); //type 1 in the chat.
Sleep(1000); //so far so good..
typeByte(VK_8); //try to use the action bar (fails)..

Sleep(1000);
TypeByte(VK_ESCAPE); //try to bring up the settings menu (fails)..
end.


This script will NEVER work with the current SMART.. In fact, if you disable SMART and you press ALT and release it and then try to use the action bar, it will never work until you undo it.. I did some digging and it turns out the only way to truly capture Alt-Tab is raw WinAPI AGAIN!! FFS..

So I decided to just write the code quick and dirty in Java.. I know for sure this works now..

Try this patch: [ATTACH=CONFIG]25190[/ATTACH]


It better work dammit.


It turns out the client doesn't register ALT + TAB at all! It registers ONLY ALT.. And when you press the tab key, that is NEVER sent to the client no matter what (unless you use WinAPI to detect it). Instead, the tab key causes it to switch already. Even if the window isn't switched, the tab key is not in the modifiers of the key event. It's not in the key code or extended key code and it's certainly not in the mask. It literally doesn't exist lol..

This makes ALT + TAB "almost" as special as CTRL + ALT + DEL..

Maybe I missed something but I doubt it.. I've been looking at this for a while.

Anyway, the above patch should fix it for sure.



CHANGE-LOG v3:


private boolean isAltDown = false; //global.

private void handleAlt() {
if (isAltDown) {
isAltDown = false;

Component canvas = clientApplet.getComponent(0);

KeyEvent alt = new KeyEvent(canvas, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), KeyEvent.ALT_DOWN_MASK, KeyEvent.VK_ALT, KeyEvent.CHAR_UNDEFINED, KeyEvent.KEY_LOCATION_LEFT);

KeyEvent tab = new KeyEvent(canvas, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), KeyEvent.ALT_DOWN_MASK, KeyEvent.VK_TAB, KeyEvent.CHAR_UNDEFINED,KeyEvent.KEY_LOCATION_STANDARD);

if (nazi != null) {
nazi.passKeyEvent(alt);
nazi.passKeyEvent(tab);
} else {
canvas.dispatchEvent(alt);
canvas.dispatchEvent(tab);
}
}
}



//In initFrame:

clientFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowActivated(WindowEvent e) {
clientFrame.requestFocusInWindow();
handleAlt();
}

@Override
public void windowDeactivated(WindowEvent e) {
handleAlt();
}

@Override
public void windowDeiconified(WindowEvent e) {
clientFrame.requestFocusInWindow();
minimized = false;
handleAlt();
}
@Override
public void windowIconified(WindowEvent e) {
minimized = true;
handleAlt();
}
@Override
public void windowClosing(WindowEvent e) {
destroy();
}
});


This will automatically release the alt key and tab key on the client itself so it "looks" like if Alt-Tab was sent and then you're all set..

I'm not sure if it's a good idea to send the tab key since the client never registered a tab down key but I did it anyway and sent a tab release.

fady

2015-03-03 21:20:20

From: Brandon
This script will NEVER work with the current SMART.. In fact, if you disable SMART and you press ALT and release it and then try to use the action bar, it will never work until you undo it.. I did some digging and it turns out the only way to truly capture Alt-Tab is raw WinAPI AGAIN!! FFS..

So I decided to just write the code quick and dirty in Java.. I know for sure this works now..

Try this patch: [ATTACH=CONFIG]25190[/ATTACH]


It better work dammit.


It turns out the client doesn't register ALT + TAB at all! It registers ONLY ALT.. And when you press the tab key, that is NEVER sent to the client no matter what (unless you use WinAPI to detect it). Instead, the tab key causes it to switch already. Even if the window isn't switched, the tab key is not in the modifiers of the key event. It's not in the key code or extended key code and it's certainly not in the mask. It literally doesn't exist lol..

This makes ALT + TAB "almost" as special as CTRL + ALT + DEL..

Maybe I missed something but I doubt it.. I've been looking at this for a while.

Anyway, the above patch should fix it for sure.


YESSSSS!!!!!!! THANK YOU!!!!!! It finally works now!!! all my scripts work when I Alt+tab out now!! So was that a problem for everyone, and no one cared or was it just me? I would rep you to infinity if I could!
Thank you very much!!!


From: Brandon
I'm not sure if it's a good idea to send the tab key since the client never registered a tab down key but I did it anyway and sent a tab release.


whenever I Alt+Tab out now a messages shows up in my chat box "You have no messages to reply to", which is what usually shows up if i just click tab in my window. But I don't care about that lol.

Thank you again!!! I really appreciate all the time you've put in with me all day!

Brandon

2015-03-03 21:25:19

From: fady
YESSSSS!!!!!!! THANK YOU!!!!!! It finally works now!!! all my scripts work when I Alt+tab out now!! So was that a problem for everyone, and no one cared or was it just me? I would rep you to infinity if I could!
Thank you very much!!!




whenever I Alt+Tab out now a messages shows up in my chat box "You have no messages to reply to", which is what usually shows up if i just click tab in my window. But I don't care about that lol.

Thank you again!!! I really appreciate all the time you've put in with me all day!



I could remove the "TAB" key so it doesn't show that message but if it doesn't matter too much, I'll leave it for now. Perhaps if this gets implemented in the official SMART and I have the pleasure of writing proper cleaner code, then I'd remove it.. For now, it won't affect you in any way. The old SMART used to write that in the chat as well. It'd only affect you if you got a message from a friend I guess..

Oh and it's a problem for EVERYONE.. Not just you. It's actually a really bad bug with the potential of breaking any script.

Glad the patch works. I'll probably remove the TAB key tomorrow or something. Don't feel like recompiling right now.

EDIT: Screw it.. I removed it. Had the compiler open already without even noticing :l Was watching Gotham.

Here: [ATTACH=CONFIG]25191[/ATTACH] That should get rid of the "No messages to reply to". I didn't test it though.

fady

2015-03-03 21:42:01

From: Brandon
I could remove the "TAB" key so it doesn't show that message but if it doesn't matter too much, I'll leave it for now. Perhaps if this gets implemented in the official SMART and I have the pleasure of writing proper cleaner code, then I'd remove it.. For now, it won't affect you in any way. The old SMART used to write that in the chat as well. It'd only affect you if you got a message from a friend I guess..

Oh and it's a problem for EVERYONE.. Not just you. It's actually a really bad bug with the potential of breaking any script.

Glad the patch works. I'll probably remove the TAB key tomorrow or something. Don't feel like recompiling right now.

EDIT: Screw it.. I removed it. Had the compiler open already without even noticing :l Was watching Gotham.

Here: [ATTACH=CONFIG]25191[/ATTACH] That should get rid of the "No messages to reply to". I didn't test it though.


Just tried it and it works great!! the scripts work when I Alt+Tab, and the message doesn't show up.

Thank you very much!! I've been having this problem since I started botting like a month ago, which is why my first script had a "keyboard fail safe" that would use the mouse to click on the action bar instead, when the keyboard didn't work. I never thought to post about it, because most of the scripts didn't have anything like that. So i assumed the problem was only me lol.

Thanks again for helping me and for your quick replies all day!