Alt modifier release event

Feature Requests, Comments, Bugs, and Suggestions on the JIntellitype Java API.

Alt modifier release event

Postby freqense » Mon Feb 15, 2016 6:21 am

I'm working on a HotKey tool for online game Dota 2 which should to simulate some keypress with Awt Robot. So, my problem is that modifier key is Alt and then I run first time from Intelij Idea my code and trying in game the registered Hotkey combination first time all work as expected, but the second time then I press again the hotkey nothing happen. I tried with delay on awt robot as you can see 2 commented lines in ghostWalk method and I realized that nothing is not simulated because when method is called to simulate keypress my finger is still on Alt key but with delay from 40-60 all work ok. (with 40 not rly, need to move out finger from alt key very fast)

So if to run code below and press registered hotkey always first time Alt + Key work as expected without any delay nothing, if to close program and run again the same thing always first time work as expected, second third etc times not. This look like first time the HotKey event is started when Alt key is released this is why all work okay all others time need the delay until Alt key is released. Is there any way to fix this ?

Code: Select all
    public void k(){
        JIntellitype.getInstance().registerHotKey(1, JIntellitype.MOD_ALT, (int)'D');
        JIntellitype.getInstance().registerHotKey(2, JIntellitype.MOD_ALT, (int)'J');
        JIntellitype.getInstance().registerHotKey(3, JIntellitype.MOD_ALT, (int)'K');
        JIntellitype.getInstance().addHotKeyListener(new HotkeyListener() {
            public void onHotKey(int aIdentifier) {

                if (aIdentifier == 1) {
                    System.out.println("WINDOWS+W hotkey pressed");
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            new L();{ghostWalk();}
                        }
                    }).start();
                }
            }
        });
    }
    //

    //
    public void ghostWalk(){
        Robot robot = null;
        try {
            robot = new Robot();
            //robot.setAutoWaitForIdle(true);
            //robot.delay(60); //60
            robot.keyPress(KeyEvent.VK_Q);
            robot.keyRelease(KeyEvent.VK_Q);
            robot.keyPress(KeyEvent.VK_Q);
            robot.keyRelease(KeyEvent.VK_Q);
            robot.keyPress(KeyEvent.VK_W);
            robot.keyRelease(KeyEvent.VK_W);
            robot.keyPress(KeyEvent.VK_R);
            robot.keyRelease(KeyEvent.VK_R);
            robot.delay(i);
            robot.keyPress(KeyEvent.VK_D);
            robot.keyRelease(KeyEvent.VK_D);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
freqense
 
Posts: 4
Joined: Mon Feb 15, 2016 5:46 am

Re: Alt modifier release event

Postby Melloware » Mon Feb 15, 2016 11:20 am

Hmmm so you are saying after the Hotkey is registered the first time you see the "WINDOWS+W Hotkey Pressed" message but then subsequent presses you do not see that message?

Only if you restart the app?

One thing to try not that it should make a difference but if you look at our example I have a class that implements HotKeyListener and I register that class to it. THe only thing I see you doing differently is the anonymous inline class registration.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
http://www.melloware.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
User avatar
Melloware
Site Admin
 
Posts: 11055
Joined: Thu Dec 01, 2005 10:24 pm
Location: Philadelphia, Pennsylvania USA

Re: Alt modifier release event

Postby freqense » Mon Feb 15, 2016 2:44 pm

Melloware wrote:Hmmm so you are saying after the Hotkey is registered the first time you see the "WINDOWS+W Hotkey Pressed" message but then subsequent presses you do not see that message?

Nope, message is printed always whenever I press the registered HotKey .
For example if to try my code in Steam store search textbox (cannot try this in browser or notepad because focus from textbox is move out when I press Alt) then all work as expected - I'm press the combination Alt + D and "qqwrd" is printed. But in game, only first time when I press the Hotkey all work as expected. This is output of 2 times press the Hotkey - "qqwrdd" where "qqwrd" is after first time and last "d" after second time, the "d" after second time is printed only because there is delay "robot.delay(i)" where i = 180.
This looks like second third etc times the method which simulate key press is started when my finger still press Alt key and nothing is printed, idk why always if to restart program always first time work as expected, the second, third time work only with start delay(60) you can see 2 commented lines in ghostWalk method.
P.S if registered Hotkey is without Alt modifier, for example only "Z" all work as expected always without delay and other sh**. I don't think that this is game limits because first time always work + I have another tool which do the same as I want to do without this problem in the same game.
freqense
 
Posts: 4
Joined: Mon Feb 15, 2016 5:46 am

Re: Alt modifier release event

Postby Melloware » Tue Feb 16, 2016 8:30 am

Hmmmm you are right I am stumped. I thought the problem was my hotkey was not registering the callback after the first time.

You are saying your code is executing it's just not doing what you expect it to do.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
http://www.melloware.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
User avatar
Melloware
Site Admin
 
Posts: 11055
Joined: Thu Dec 01, 2005 10:24 pm
Location: Philadelphia, Pennsylvania USA

Re: Alt modifier release event

Postby freqense » Tue Feb 16, 2016 9:18 am

Melloware wrote:Hmmmm you are right I am stumped. I thought the problem was my hotkey was not registering the callback after the first time.

You are saying your code is executing it's just not doing what you expect it to do.

Exactly, you can try my code in skype to see what exactly happens, in skype the focus is too moving out on a top tabs from a moment and first "q" is not printing but anyway in the rest the code behavior is exactly like in game after first time only "D" is simulated.
I tried to look in the source code to understand what changes are made after first event but I'm newbie and the source looks for me like chinese. Did you have any idea how to fix this ?
Here is my all code from first to last line. Dll x64.

Code: Select all
import com.melloware.jintellitype.HotkeyListener;
import com.melloware.jintellitype.JIntellitype;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

public class L {
    int i = 180;
    int runeId = 1;

    public static void main(String args[]){
        try{
            L rf = new L();
            rf.k();
        }
        catch (Exception e){

        }
    }
    public void k(){
        JIntellitype.getInstance().registerHotKey(1, JIntellitype.MOD_ALT, (int)'D');
        JIntellitype.getInstance().registerHotKey(2, JIntellitype.MOD_ALT, (int)'J');
        JIntellitype.getInstance().registerHotKey(3, JIntellitype.MOD_ALT, (int)'K');
        JIntellitype.getInstance().addHotKeyListener(new HotkeyListener() {
            public void onHotKey(int aIdentifier) {
                if (aIdentifier == 1) {
                    System.out.println("WINDOWS+W hotkey pressed");
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            new L();{ghostWalk();}
                        }
                    }).start();
                }
            }
        });
    }
    //

    //
    public void ghostWalk(){
        Robot robot = null;
        try {

            robot = new Robot();
            //robot.setAutoWaitForIdle(true);
            //robot.delay(60); //60
            robot.keyPress(KeyEvent.VK_Q);
            robot.keyRelease(KeyEvent.VK_Q);
            robot.keyPress(KeyEvent.VK_Q);
            robot.keyRelease(KeyEvent.VK_Q);
            robot.keyPress(KeyEvent.VK_W);
            robot.keyRelease(KeyEvent.VK_W);
            robot.keyPress(KeyEvent.VK_R);
            robot.keyRelease(KeyEvent.VK_R);
            robot.delay(i);
            robot.keyPress(KeyEvent.VK_D);
            robot.keyRelease(KeyEvent.VK_D);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
freqense
 
Posts: 4
Joined: Mon Feb 15, 2016 5:46 am

Re: Alt modifier release event

Postby Melloware » Tue Feb 16, 2016 4:46 pm

Nothing I see sticks out to me.

is the creation of the Robot() class expensive i wonder if that should just be instantiated once?
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
http://www.melloware.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
User avatar
Melloware
Site Admin
 
Posts: 11055
Joined: Thu Dec 01, 2005 10:24 pm
Location: Philadelphia, Pennsylvania USA

Re: Alt modifier release event

Postby freqense » Tue Feb 16, 2016 5:55 pm

Melloware wrote:Nothing I see sticks out to me.

is the creation of the Robot() class expensive i wonder if that should just be instantiated once?

I have no idea, I tried now and if he is initiated somewhere else than ghostWalk method then only "D" is printed always even first time. With no modifier for example only "Z" key then no matter where and how it is initiated this work always like it should. Well, maybe I'm not doing right, can you suggest how it should to be initiated? Tried it as static initiated in main() method also tried as non static initiated only one time in k() method, idk what is wrong, this just fucked up my brain.
freqense
 
Posts: 4
Joined: Mon Feb 15, 2016 5:46 am


Return to JIntellitype

Who is online

Users browsing this forum: No registered users and 1 guest

cron