Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same instance getting fired #4

Open
ghost opened this issue May 2, 2018 · 10 comments
Open

Same instance getting fired #4

ghost opened this issue May 2, 2018 · 10 comments

Comments

@ghost
Copy link

ghost commented May 2, 2018

I have p+0 and m+0 assigned.
I saw that when I m+0 is pressed, it shows p+0 as keyname.
Here is the code.

onKeyDown(keyName, e, handle) {
        const key = handle.key;
        console.log(handle);
        switch (key) {
            case 'p+0':
            case 'p+1':
            case 'p+2':
            case 'p+3':
            case 'p+4':
            case 'p+5':
            case 'p+6':
            case 'p+7':
            case 'p+8':
            case 'p+9':
                try {
                    const currentPosition = this.giveWarningIfNoPositionSelected();
                    let openingSize = key.replace(/(p\+)/i, '');
                    if (openingSize === '0') {
                        openingSize = parseFloat(currentPosition.quantity);
                    } else {
                        const percentage = parseFloat(openingSize) * 10;
                        openingSize = (parseFloat(currentPosition.quantity) * percentage) / 100;
                    }
                    const openingPositionSide = /-/.test(openingSize) ? 'sell' : 'buy';
                    const msg = 'Placing ' + openingPositionSide + ' market order for ' + currentPosition.symbol + ' on ' +
                        strCapitalize(currentPosition.exchange_name) + '' +
                        ' with qty ' + openingSize;
                    if (window.confirm(msg)) {
                        const data = {
                            exchange_name: currentPosition.exchange_name.toLowerCase(),
                            symbol: currentPosition.ccxt_symbol,
                            type: 'market',
                            side: openingPositionSide,
                            quantity: parseFloat(openingSize),
                            time_in_force: 'GTC'
                        };
                        this.placeOrder(data);
                    }
                } catch (e) {

                }
                break;
            case 'm+0':
            case 'm+1':
            case 'm+2':
            case 'm+3':
            case 'm+4':
            case 'm+5':
            case 'm+6':
            case 'm+7':
            case 'm+8':
            case 'm+9':
                console.log('here');
                break;
        }

So, when I basically press m+9, the code in p+n is getting executed and it's showing me the confirm which should not happen.
A quick reply would be appreciated.
Thank you in advance.

@jaywcjlove
Copy link
Owner

@koushik72 Must be combined with modifier keys

const _modifier = { // 修饰键
  '⇧': 16,
  shift: 16,
  '⌥': 18,
  alt: 18,
  option: 18,
  '⌃': 17,
  ctrl: 17,
  control: 17,
  '⌘': isff ? 224 : 91,
  cmd: isff ? 224 : 91,
  command: isff ? 224 : 91,
};

@ghost
Copy link
Author

ghost commented May 8, 2018

Hi, thank you for the reply.
I have these two now.
shift+c+1 and shift+m+0. When I press shift+m+0, the code for shift+c+1 gets fired.
Why is that?

@jaywcjlove
Copy link
Owner

jaywcjlove commented May 8, 2018

@koushik72

ctrl+shift+1 and ctrl+shift+2
or
ctrl+alt+1 and ctrl+alt+2

@jaywcjlove
Copy link
Owner

image

@koushik72 Shortcut definition

  • modifier key + key
  • modifier key + modifier key + key
  • modifier key + modifier key + modifier key + key

@ghost
Copy link
Author

ghost commented May 9, 2018

I can't see those Chinese texts. I can only understand those shortcut icon.
I have one question. Is it possible to execute different code when shift+c and shift+p are pressed?
Thank you.

@jaywcjlove
Copy link
Owner

I have one question. Is it possible to execute different code when shift+c and shift+p are pressed?
of course can

Of course you can execute different code

@ghost
Copy link
Author

ghost commented May 9, 2018

But I am having trouble with that part.
I have these keys
const keynames = 'up,w,s, down, shift+c+0, shift+d+0';
Now for onKeyDown event when I check the name, it shows the keyname as
shift+c+0 even when I pressed shift+d+0.
Why is that?

@jaywcjlove
Copy link
Owner

jaywcjlove commented May 9, 2018

@koushik72

bad

Does not support modifier key + key + key

shift+c+0

  • shift => modifier key
  • c => key
  • 0 => key

good

Support modifier key + modifier key + key

shift+ alt +0

  • shift => modifier key
  • alt => modifier key
  • 0 => key

@ghost
Copy link
Author

ghost commented May 10, 2018

Hi, thank you for the clarification, That did help me. Do you know any library that supports it?

@jaywcjlove
Copy link
Owner

I do not know. If you know, please tell me. thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant