How to make the computer think that a key has been pressed?

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Evan
Coder
Posts: 21
Joined: Wed Dec 27, 2006 6:03 pm
Location: Weatherford TX

How to make the computer think that a key has been pressed?

Post by Evan » Mon Jan 15, 2007 4:43 pm

How can you make the computer think that a key has been pressed?
Evan Hurd

Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re » Mon Jan 15, 2007 5:22 pm

SendKeys

Windows API

Use FreeBASIC, cant be done in QBASIC
I have left this dump.

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Re: How to make the computer think that a key has been press

Post by moneo » Mon Jan 15, 2007 7:20 pm

Evan wrote:How can you make the computer think that a key has been pressed?
You can do this in QB by using INKEY$ or ON KEY.

But you should expalin in more detail what you need or want to do.

Regards..... Moneo

comperr
Newbie
Posts: 4
Joined: Mon Dec 18, 2006 1:10 pm

Post by comperr » Mon Jan 15, 2007 11:00 pm

In QBasic you would have to use CALL ABSOLUTE to call proccesser interupts in assembaly.

Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re » Tue Jan 16, 2007 5:42 am

comperr wrote:In QBasic you would have to use CALL ABSOLUTE to call proccesser interupts in assembaly.
Only works in pure DOS mode.
I have left this dump.

User avatar
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations » Wed Jan 17, 2007 8:52 am

I was wondering the same thing: I've been developing a virtual keyboard program, and was wondering how to do this in QB. What ABSOLUTE calls would you have to make?

User avatar
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Re: How to make the computer think that a key has been press

Post by Patz QuickBASIC Creations » Wed Jan 17, 2007 4:37 pm

moneo wrote:
Evan wrote:How can you make the computer think that a key has been pressed?
You can do this in QB by using INKEY$ or ON KEY.

But you should expalin in more detail what you need or want to do.

Regards..... Moneo
He made a post about a keylogger before... So I'm guessing he wants to make a program that gets a key (before the OS does), record it, and then pass it to the OS. That way, you have a "keylogger". Records every key pressed, without the knowledge of a more advanced user.

Is that right...?

User avatar
seaBiscuit$
Coder
Posts: 45
Joined: Sun Nov 26, 2006 2:00 pm
Location: Champaign, Illinois

Re: How to make the computer think that a key has been press

Post by seaBiscuit$ » Wed Jan 17, 2007 6:30 pm

Patz QuickBASIC Creations wrote:
moneo wrote:
Evan wrote:How can you make the computer think that a key has been pressed?
You can do this in QB by using INKEY$ or ON KEY.

But you should expalin in more detail what you need or want to do.

Regards..... Moneo
He made a post about a keylogger before... So I'm guessing he wants to make a program that gets a key (before the OS does), record it, and then pass it to the OS. That way, you have a "keylogger". Records every key pressed, without the knowledge of a more advanced user.

Is that right...?
That shneakyshneaky Evan. :)

Maybe I'm wrong, but I don't think the keys would register if the program was running in the background, even if it's reading them directly from the keyboard port, at least in WinXP or something. It might work in a dos based os like Win95, but I'm still not sure. :?

Maybe QB isn't the right tool for the job.
sid6.7 wrote:everytime i see your avatar i want to scream and kill it.... :)

User avatar
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Re: How to make the computer think that a key has been press

Post by Nodtveidt » Wed Jan 17, 2007 9:57 pm

seaBiscuit$ wrote:Maybe I'm wrong, but I don't think the keys would register if the program was running in the background, even if it's reading them directly from the keyboard port, at least in WinXP or something. It might work in a dos based os like Win95, but I'm still not sure. :?

Maybe QB isn't the right tool for the job.
You would need to use the GetAsyncKeyState API call, it picks up keystates whether the parent application has focus or not. But I don't think that that's what he's looking for...it looks more like what he wants is a program that enters keystrokes by itself, in which case, SendKeys will do the job.

User avatar
seaBiscuit$
Coder
Posts: 45
Joined: Sun Nov 26, 2006 2:00 pm
Location: Champaign, Illinois

Re: How to make the computer think that a key has been press

Post by seaBiscuit$ » Thu Jan 18, 2007 10:02 pm

Nekrophidius wrote:You would need to use the GetAsyncKeyState API call, it picks up keystates whether the parent application has focus or not. But I don't think that that's what he's looking for...it looks more like what he wants is a program that enters keystrokes by itself, in which case, SendKeys will do the job.
Is it possible to use Windows API calls in QB? I'm thinking that maybe writing something in C that can be called with SHELL or piped through the QB program might work for that.
sid6.7 wrote:everytime i see your avatar i want to scream and kill it.... :)

User avatar
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Re: How to make the computer think that a key has been press

Post by Nodtveidt » Fri Jan 19, 2007 6:14 am

seaBiscuit$ wrote:Is it possible to use Windows API calls in QB?
No, it's not.
seaBiscuit$ wrote:I'm thinking that maybe writing something in C that can be called with SHELL or piped through the QB program might work for that.
What might help is if you state your true intentions rather than dancing around the mulberry bush, know what I mean?

User avatar
seaBiscuit$
Coder
Posts: 45
Joined: Sun Nov 26, 2006 2:00 pm
Location: Champaign, Illinois

Re: How to make the computer think that a key has been press

Post by seaBiscuit$ » Fri Jan 19, 2007 7:25 pm

Nekrophidius wrote:What might help is if you state your true intentions rather than dancing around the mulberry bush, know what I mean?
I'm not actually going to try this, if that's what you mean. I'm busy with my own projects as well as school. I was just suggesting a method that might work.
sid6.7 wrote:everytime i see your avatar i want to scream and kill it.... :)

User avatar
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt » Sat Jan 20, 2007 5:43 am

Sorry, that should have been directed towards Evan. Although I think we all know his true intentions...

Evan
Coder
Posts: 21
Joined: Wed Dec 27, 2006 6:03 pm
Location: Weatherford TX

Post by Evan » Mon Jan 22, 2007 8:59 pm

Actually I trying to make a program that keeps the screen saver from coming on. :D
Evan Hurd

User avatar
seaBiscuit$
Coder
Posts: 45
Joined: Sun Nov 26, 2006 2:00 pm
Location: Champaign, Illinois

Post by seaBiscuit$ » Mon Jan 22, 2007 11:13 pm

Oh really???

What about your keylogger post?

You know... You can set the screen saver to NONE..... :wink:
sid6.7 wrote:everytime i see your avatar i want to scream and kill it.... :)

Evan
Coder
Posts: 21
Joined: Wed Dec 27, 2006 6:03 pm
Location: Weatherford TX

Post by Evan » Tue Jan 23, 2007 3:15 pm

Yes but when you have big brothers that do not like you on the computer it?s really fun to see them try and figure-out why the screen saver is not on. :)
But now I made a program that keeps a user off a program without a password.


:twisted:
Evan Hurd

User avatar
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations » Sat Jan 27, 2007 12:49 pm

Well, as I wouldn't use this as a keylogger or whatever, I am still curious as to what you would have to do. I want to make a "virtual keyboard" program for my TUI.

Evan
Coder
Posts: 21
Joined: Wed Dec 27, 2006 6:03 pm
Location: Weatherford TX

Post by Evan » Mon Jan 29, 2007 9:58 am

I have no idea.
Evan Hurd

User avatar
Seb McClouth
Veteran
Posts: 342
Joined: Wed Nov 09, 2005 7:47 am
Location: Inside the Matrix...
Contact:

Post by Seb McClouth » Tue Jan 30, 2007 2:22 am

Patz QuickBASIC Creations wrote:Well, as I wouldn't use this as a keylogger or whatever, I am still curious as to what you would have to do. I want to make a "virtual keyboard" program for my TUI.
Hey Patz, not sure if I can be of any help but pm me about this. We'll see what's possible!

Grtz
Seb
QBinux is a Linux distribution with the aim of integrating the work of the vast community of free software developers at Pete's QBASIC Site in order to create a modern, performant, safe and easy to use system for system administrators and desktop users.

User avatar
burger2227
Veteran
Posts: 2333
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 » Thu Feb 15, 2007 1:44 pm

You can OUT a key value using &H60 on 98 and older machines. XP will not allow changes to settings in the BIOS keyboard including lites.

Try the following to get the key press and release codes.

Do: press$ = INKEY$
code = INP(&H60)
locate 20, 20: PRINT press$; code
LOOP UNTIL press$ = CHR$(27)

The release code is 128 more than the press code. Numbers Lock may mess up the shift and arrow key codes returned however. If both shift keys = 170 then change the numbers lock mode. I have a list of many DOS BIOS routines. Just email me with DOS BIOS in message! :lol:

Post Reply