skol-pro / ion-digit-keyboard-v2

A digital keyboard plugin to use in Ionic 2 applications.
MIT License
94 stars 40 forks source link

How to switch between numbers keypad to alphabets keypad #24

Closed chaitanyas11 closed 5 years ago

chaitanyas11 commented 5 years ago

hi

How to switch between numbers keypad to alphabets keypad, its working for numbers but how to switch between from this numbers to alphabets what are displaying on keyboard. I need how to set the settings for this, please help me i need in Angular 5 please do need full Screenshot_20190613_112801

skol-pro commented 5 years ago

Well there is no default handling for typing letters. You'll need to bind it your-self.

this.keyboard.onClick.subscribe((key) => {
    if (key === 2) {
        // You can handle multiple press with a timeout to switch between A, B or C
    }
    if (key === 3) {
        // ...
    }
    // ...
});
chaitanyas11 commented 5 years ago

hi,

would u please provide me atleast multiple press logic for any one button.

thanks and regards, chaitanya

skol-pro commented 5 years ago

I wrote it quickly, haven't been able to test it, so give it a test and tell me.

<input type="text" [(ngModel)]="model">
public model = '';

private lastKey;
private keyCount = -1;
private keyPressTimeout;
private keyMapping = {
    2: ['A', 'B', 'C'],
    3: ['D', 'E', 'F'],
    4: ['G', 'H', 'I'],
    5: ['J', 'K', 'L'],
    6: ['M', 'N', 'O'],
    7: ['P', 'Q', 'R', 'S'],
    8: ['T', 'U', 'V'],
    9: ['W', 'X', 'Y', 'Z']
};

// ...

constructor() {

    this.keyboard.onClick.subscribe((key) => {
        if (this.keyPressTimeout) clearTimeout(this.keyPressTimeout);

        if (this.keyMapping[key]) {
            if (key === this.lastKey) {
                this.keyCount++;
            }

            const letter = this.keyMapping[key][this.keyCount % this.keyMapping[key].length];

            if (this.keyCount === 0) {
                this.model += letter;
            } else {
                this.model = this.model.slice(0, -1) + letter;
            }

            this.lastKey = key;

            this.keyPressTimeout = setTimeout(() => {
                this.keyCount = -1;
                this.lastKey = null;
            }, 300);
        }
    });
}
skol-pro commented 5 years ago

And in case you want the lowercase before uppercase, just replace the keyMapping by:

private keyMapping = {
    2: ['a', 'b', 'c', 'A', 'B', 'C'],
    3: ['d', 'e', 'f', 'D', 'E', 'F'],
    4: ['g', 'h', 'i', 'G', 'H', 'I'],
    5: ['j', 'k', 'l', 'J', 'K', 'L'],
    6: ['m', 'n', 'o', 'M', 'N', 'O'],
    7: ['p', 'q', 'r', 's', 'P', 'Q', 'R', 'S'],
    8: ['t', 'u', 'v', 'T', 'U', 'V'],
    9: ['w', 'x', 'y', 'z', 'W', 'X', 'Y', 'Z']
};
chaitanyas11 commented 5 years ago

its giving length error it as undefined

chaitanyas11 commented 5 years ago

can't we do toggle of number keypad and alphabetic keypad with the help of shift button

chaitanyas11 commented 5 years ago

alphanumeric keypad 3

as like this

skol-pro commented 5 years ago

Oups, I modified the line in my original comment.

const letter = this.keyMapping[key][this.keyCount % this.keyMapping[key].length];

Not sure to understand your two last comments.

chaitanyas11 commented 5 years ago

As of now u developed this keypad Screenshot_20190614_164255

chaitanyas11 commented 5 years ago

my doubt is that if we add extra button like alpha-numeric keypad

this button to above keyboard

chaitanyas11 commented 5 years ago

then can we toggle from only numbers keypad to only alphabets keypad

that is possible with this,

chaitanyas11 commented 5 years ago

Oups, I modified the line in my original comment.

const letter = this.keyMapping[key][this.keyCount % this.keyMapping[key].length];

Not sure to understand your two last comments.