Qbasicnews.com
Sending data to keyboard? - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html)
+--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html)
+--- Thread: Sending data to keyboard? (/thread-2445.html)

Pages: 1 2


Sending data to keyboard? - Meg - 11-10-2003

I'm no master of the OUT command (assuming that's what's used for this), so maybe somebody here can help me:

I'm trying to figure out how to manipulate data in such as way as to make it seem to be coming from the keyboard.

I've got a barcode scanner that hooks up RS232 (Com1 on my comp). My program opens up Com1 via the OPEN command, reads data from it, and displays it to the screen.

This part works. I can scan a barcode with the scanner, and it appears on the screen fine (via PRINT command).

What I want is to be able to, say, open Notepad and read a barcode with the scanner, and have the text appear in Notepad.

I think this might be possible by having my program run in the background, reading data from COM1: and sending it to the port that the keyboard hooks up to. Correct me if I'm wrong.

If anybody know how to do this, or has any suggestions, etc, please let me know.

Thanks in advance,

Meg.

(*peace*)


Sending data to keyboard? - red_Marvin - 11-10-2003

I can't really help you but I doubt QB is the way to go...
I think you should search for facts about TSR's
(Terminate and Stay Resident, a program that
loads itself in memory, hooks up on a event function and ends, but
the program stays in memory and gets called everytime the event
it hooked up on is executed -I think)


Sending data to keyboard? - Plasma - 11-10-2003

You can stuff keystrokes with QB, but they will only be "faked" in the DOS box...they won't show up in Windows. If you really want to use QB, you can copy the text to the clipboard with an interrupt and then paste it in notepad...not exactly the same though.

However, if you use VB, you can stuff keystrokes in Windows...


Sending data to keyboard? - na_th_an - 11-10-2003

Yeah, in VB the code would be almost the same (the QB part) _AND_ the keystrokes can be generated with 1 line of code (windows API).


thank you for the replies - Meg - 11-11-2003

Thanks everyone for the prompt replies.

I might look into the VB thing, although I see there are some existing "software keyboard wedges" out there that do this exact thing for a fairly cheap cost, so I might just grab one of those instead.

If I do try to write something up in VB, what's the single line of code used to stuff the kb data?

*peace*

Meg.


Sending data to keyboard? - TheBigBasicQ - 11-11-2003

Ok guys take it easy now. Dont kill me. I am not preaching any language here... :rotfl:

Meg, I suggest you use C since I see you here asking about low level stuff.

*Runs to his closet and puts on his helmet Wink*

*Wham Bam! !$@%^$kill him!#$@$#@*

*Ends up in the hospital*


Sending data to keyboard? - na_th_an - 11-11-2003

No low level, my friend Wink Just one call: SendKeys.

For example, this code

Code:
SUB Main()
   Shell "notepad", vbNormalFocus
   SendKeys "Hey, there's a ghost in your desktop"
END SUB

Will open Notepad and write on it Wink

There are special codes for special keys:

BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER}or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}

So if you wanna generate for example a code and then ENTER, you just...

Code:
SendKey code$+"{ENTER}"

Me and Phobeous used this to write a Smart Card reader in VB last year at college Wink. It just read the data from the COM port, interpreted it, and sent the keys to MSIE to validate people remotely.


Sending data to keyboard? - Moneo - 11-11-2003

MEG,
The following should work if you are running form the MSDOS prompt.
Code:
' The following is from Ethan Winer's book.
'StuffBuffer subprogram shown below inserts a string of up to 15 characters
'directly into the keyboard buffer.  It works by poking each character one
'by one into the buffer address in low memory.  Thus, when your program ends
'the characters are there as if someone had typed them manually.

DEFINT A-Z
DECLARE SUB StuffBuffer (Cmd$)

SUB StuffBuffer (Cmd$) STATIC

  '----- Limit the string to 14 characters plus Enter and save the length.
  Work$ = LEFT$(Cmd$, 14) + CHR$(13)
  Length = LEN(Work$)

  '----- Set the segment for poking, define the buffer head and tail, and
  '      then poke each character.
  DEF SEG = 0
  POKE 1050, 30
  POKE 1052, 30 + Length * 2
  FOR X = 1 TO Length
    POKE 1052 + X * 2, ASC(MID$(Work$, X))
  NEXT

END SUB



Sending data to keyboard? - Plasma - 11-11-2003

She wants to send the keystrokes to a Windows program though (Notepad)...so that won't work.


Thanks all for replies - Meg - 11-11-2003

Na_th_an, thanks a bunch, and everybody else who contributed.

*peace*

Meg.