How to focus on a line edit and start typing using another keypad in linux
Hello Guys ,I am trying to make an program with the use of a normal keypad instead of a keyboard . And I am doing it in linux environment , using a imx53 board. What i can do now is jus make the keypad type in just one line edit without even focusing on the lineEdit at all .Here is the codes
Code:
void LoginGui::CheckKeypadPressed()
{
if(key_Available()==1)
{
int CheckNumber;
CheckNumber=key_Get();
if(CheckNumber==1)
{
ui->password->setText(ui->password->text()+"1");
}
if(CheckNumber==2)
{
ui->password->setText(ui->password->text()+"2");
}
if(CheckNumber==3)
{
ui->password->setText(ui->password->text()+"3");
}
if(CheckNumber==4)
{
ui->password->setText(ui->password->text()+"4");
}
if(CheckNumber==5)
{
ui->password->setText(ui->password->text()+"5");
}
if(CheckNumber==6)
{
ui->password->setText(ui->password->text()+"6");
}
if(CheckNumber==7)
{
ui->password->setText(ui->password->text()+"7");
}
if(CheckNumber==8)
{
ui->password->setText(ui->password->text()+"8");
}
if(CheckNumber==9)
{
ui->password->setText(ui->password->text()+"9");
}
}
What i am going to do now is to have 2 line edit . And i want to use the keypad for 2 line edits , Currently the Codes i have can't even use for 2 line edit .
What i am thinking is making an "if" statement to focus on 2 different line edits . I am do not know how to do this , Please Help me
Re: How to focus on a line edit and start typing using another keypad in linux
Does the keypad appear as an input device to Linux? If that's the case I would have expected it to just work like any other keyboard.
Anyway, you can use the Qt Event system to inject key press and release events into the input of whatever widget has focus. The widget will handle the key press however it normally would.
Code:
#include <QtGui>
{
Q_OBJECT
public:
setLayout(layout);
// Organise some fake keyboard activity
connect(timer, SIGNAL(timeout()), SLOT(fakeKeyPress()));
timer->setInterval(500);
timer->start();
}
private slots:
void fakeKeyPress() {
if (focussed) {
}
}
};
int main(int argc, char **argv)
{
Window w;
w.show();
return app.exec();
}
#include "main.moc"
Re: How to focus on a line edit and start typing using another keypad in linux
I am using a IMX53 board . and the keypad is connected to a GPIO pin on the board .
I am Still unclear of the QKeyEvent parts, Is there other ways i can do it ?
Added after 53 minutes:
Quote:
Originally Posted by
ChrisW67
Does the keypad appear as an input device to Linux? If that's the case I would have expected it to just work like any other keyboard.
Anyway, you can use the Qt Event system to inject key press and release events into the input of whatever widget has focus. The widget will handle the key press however it normally would.
Code:
#include <QtGui>
{
Q_OBJECT
public:
setLayout(layout);
// Organise some fake keyboard activity
connect(timer, SIGNAL(timeout()), SLOT(fakeKeyPress()));
timer->setInterval(500);
timer->start();
}
private slots:
void fakeKeyPress() {
if (focussed) {
}
}
};
int main(int argc, char **argv)
{
Window w;
w.show();
return app.exec();
}
#include "main.moc"
I tried some trial and errors with your codes , I tried doing this , Not sure whether it is the right way to do it .
Code:
void PatientGui:: fakeKeyPress() {
QWidget *focussed
= ui
->nric
->focusWidget
();
if (focussed) {
if(key_Available()==1)
{
int CheckNumber;
CheckNumber=key_Get();
if(CheckNumber==1)
{
ui->nric->setText(ui->nric->text()+"1");
}
if(CheckNumber==2)
{
ui->nric->setText(ui->nric->text()+"2");
}
if(CheckNumber==3)
{
ui->nric->setText(ui->nric->text()+"3");
}
if(CheckNumber==4)
{
ui->nric->setText(ui->nric->text()+"4");
}
if(CheckNumber==5)
{
ui->nric->setText(ui->nric->text()+"5");
}
if(CheckNumber==6)
{
ui->nric->setText(ui->nric->text()+"6");
}
if(CheckNumber==7)
{
ui->nric->setText(ui->nric->text()+"7");
}
if(CheckNumber==8)
{
ui->nric->setText(ui->nric->text()+"8");
}
if(CheckNumber==9)
{
ui->nric->setText(ui->nric->text()+"9");
}
}
QWidget *focussed1
= ui
->bednumber
->focusWidget
();
if (focussed1) {
if(key_Available()==1)
{
int CheckNumber;
CheckNumber=key_Get();
if(CheckNumber==1)
{
ui->password->setText(ui->password->text()+"1");
}
if(CheckNumber==2)
{
ui->password->setText(ui->password->text()+"2");
}
if(CheckNumber==3)
{
ui->password->setText(ui->password->text()+"3");
}
if(CheckNumber==4)
{
ui->password->setText(ui->password->text()+"4");
}
if(CheckNumber==5)
{
ui->password->setText(ui->password->text()+"5");
}
if(CheckNumber==6)
{
ui->password->setText(ui->password->text()+"6");
}
if(CheckNumber==7)
{
ui->password->setText(ui->password->text()+"7");
}
if(CheckNumber==8)
{
ui->password->setText(ui->password->text()+"8");
}
if(CheckNumber==9)
{
ui->password->setText(ui->password->text()+"9");
}
}
}
Can I do this ?
Re: How to focus on a line edit and start typing using another keypad in linux
Typically you'd address this by writing/using a Linux device driver that interfaces the hardware to the Linux input events system. The rest would flow naturally from that. There are GPIO keyboard modules in the mainline kernel... Device Drivers -> GPIO Support and Device Drivers -> Input device support -> Keyboards. I don't know if that is useful on your board.
If you must do it in your program. How does your program get notified that a key is pressed and/or released? Is an interrupt generated or are you expected to poll? Essentially the code in my fakeKeyPress() routine is the sort of code you should execute when you hear of a key being pressed. You need to generate appropriate QKeyEvents for the keys pressed.
Re: How to focus on a line edit and start typing using another keypad in linux
Basically , i put my keypad codes in a timer . Currently i am facing a problem where by i can only key in one line edit and only can key in in the line edit , when i got to the next page , i cant type at all,and when i go back to the first page , same things happened
What i am doing is a group project , the keypad part is from another guy , he put it into a threat and keep checking for the button press and returning a value to me for the number pressed .the keypad is connected to the keypad pin on the board.
Added after 28 minutes:
Anyway i tried running your codes , it will keep input 1 without any keys being pressed in windows qt
Re: How to focus on a line edit and start typing using another keypad in linux
Ok i tried the method u have give with my keypad codes, It works without this
Quote:
There are GPIO keyboard modules in the mainline kernel... Device Drivers -> GPIO Support and Device Drivers -> Input device support -> Keyboards.
.I only implented the "fakekeypress()" once in a cpp file . And i am suprised it works on other Ui even though i did not implement the "fakeKeypress()" in its cpp file ,, Is there a reason for it ?