send function keys to a legacy DOS program

J

Justin Ezequiel

Greetings,

We have an old barcode program (MSDOS and source code unavailable.)
I've figured out how to populate the fields (by hacking into one of
the program's resource files.)
However, we still need to hit the following function keys in sequence.
F5, F2, F7
Is there a way to pipe said keys into the program?

I know it's not really a python problem but I got nowhere else to go.
I've tried other barcode solutions but none give the same output.
 
M

MRAB

Greetings,

We have an old barcode program (MSDOS and source code unavailable.)
I've figured out how to populate the fields (by hacking into one of
the program's resource files.)
However, we still need to hit the following function keys in sequence.
F5, F2, F7
Is there a way to pipe said keys into the program?

I know it's not really a python problem but I got nowhere else to go.
I've tried other barcode solutions but none give the same output.
One (hacky) solution is to use the sendkeys module:

http://www.rutherfurd.net/python/sendkeys/

First enumerate the windows and get the title and handle of each:

import win32gui

def enum_windows(accept=None):
def callback(handle, data):
title = win32gui.GetWindowText(handle)
windows.append((title, handle))
windows = []
win32gui.EnumWindows(callback, None)
return windows

Identify the target window's handle by its title and give that window
the input focus:

win32gui.SetForegroundWindow(handle)

Then use the sendkeys module to simulate the keypresses.
 
J

jr

Greetings,

We have an old barcode program (MSDOS and source code unavailable.)
I've figured out how to populate the fields (by hacking into one of
the program's resource files.)
However, we still need to hit the following function keys in sequence.
F5, F2, F7
Is there a way to pipe said keys into the program?

Use "expect" on unix or "pexpect" if you're looking for the python
implementation.
 
E

Emile van Sebille

On 3/10/2011 4:58 PM Justin Ezequiel said...
Greetings,

We have an old barcode program (MSDOS and source code unavailable.)
I've figured out how to populate the fields (by hacking into one of
the program's resource files.)
However, we still need to hit the following function keys in sequence.
F5, F2, F7
Is there a way to pipe said keys into the program?

I know it's not really a python problem but I got nowhere else to go.
I've tried other barcode solutions but none give the same output.
WSH sendkeys?

Emile
 
A

Alexander Gattin

Hello,

We have an old barcode program (MSDOS and source code unavailable.)
I've figured out how to populate the fields (by hacking into one of
the program's resource files.)
However, we still need to hit the following function keys in sequence.
F5, F2, F7
Is there a way to pipe said keys into the program?

It's a very old and good known trick IMO. You just
need to write keycodes to kbd ring buffer in BIOS
data area (I don't remember exact address,
soemewhere in 1st 4kbytes of PC memory), then wait
till the scancode gets consumed. I'd put "scancode
feeding" code into timer interrupt handler.
 
A

Alexander Gattin

It's a very old and good known trick IMO. You just
need to write keycodes to kbd ring buffer in BIOS
data area (I don't remember exact address,
soemewhere in 1st 4kbytes of PC memory), then wait
till the scancode gets consumed. I'd put "scancode
feeding" code into timer interrupt handler.

Taken from RBIL/MEMORY.LST
(http://www.cs.cmu.edu/~ralf/interrupt-list/inter61c.zip):

--------K-M0040001A--------------------------
MEM 0040h:001Ah - KEYBOARD - POINTER TO NEXT CHARACTER IN KEYBOARD BUFFER
Size: WORD
SeeAlso: MEM 0040h:001Ch,MEM 0040h:0080h,MEM 0040h:0082h,INT 16/AH=00h
--------K-M0040001C--------------------------
MEM 0040h:001Ch - KEYBOARD - POINTER TO FIRST FREE SLOT IN KEYBOARD BUFFER
Size: WORD
SeeAlso: MEM 0040h:001Ah,MEM 0040h:001Eh,MEM 0040h:0080h,MEM 0040h:0082h
SeeAlso: INT 16/AH=00h
--------K-M0040001E--------------------------
MEM 0040h:001Eh - KEYBOARD - DEFAULT KEYBOARD CIRCULAR BUFFER
Size: 16 WORDs
SeeAlso: MEM 0040h:001Ah,MEM 0040h:001Ch,MEM 0040h:0080h,MEM 0040h:0082h
SeeAlso: INT 16/AH=00h,INT 16/AH=05h

Buffer is considered empty if
word[0x41A]==word[0x41C] IIRC.

You need to place 2 bytes into the circular buffer
to simulate key press. Lower byte is ASCII code,
higher byte is scan code (they are the same for
functional keys, whe using default keycode set#1):

F5: 0x3F 0x3F
F2: 0x3C 0x3C
F7: 0x41 0x41
 
J

John Nagle

Greetings,

We have an old barcode program (MSDOS and source code unavailable.)
I've figured out how to populate the fields (by hacking into one of
the program's resource files.)
However, we still need to hit the following function keys in sequence.
F5, F2, F7
Is there a way to pipe said keys into the program?

I know it's not really a python problem but I got nowhere else to go.
I've tried other barcode solutions but none give the same output.

Look into DOSbox.

http://www.dosbox.com

It's an open-source software emulator for an x86 machine running DOS.
So you can go into the emulator and connect to the "keyboard" or
"screen" from another program.

John Nagle
 
L

LehH Sdsk8

Greetings,

We have an old barcode program (MSDOS and source code unavailable.)
I've figured out how to populate the fields (by hacking into one of
the program's resource files.)
However, we still need to hit the following function keys in sequence.
F5, F2, F7
Is there a way to pipe said keys into the program?

I know it's not really a python problem but I got nowhere else to go.
I've tried other barcode solutions but none give the same output.

You should try these links:
http://www.rhinocerus.net/forum/lang-asm-x86/254441-re-how-write-char-keyboard-buffer.html
http://bytes.com/topic/c/answers/212952-keyboard-buffer
http://bytes.com/topic/c/answers/747883-writing-into-keyboard-buffer-aix
 
J

Justin Ezequiel

On Sun, Mar 20, 2011 at 12:52:28AM +0200,

You need to place 2 bytes into the circular buffer
to simulate key press. Lower byte is ASCII code,
higher byte is scan code (they are the same for
functional keys, whe using default keycode set#1):

F5: 0x3F 0x3F
F2: 0x3C 0x3C
F7: 0x41 0x41

looks promising. will give this a try. thanks!
 
A

Alexander Gattin

Hello,


I'm not sure regarding the ASCII part. I think it
might need to be set to 0x00 for all functional
keys instead of 0x3F/0x3C/0x41, but probably no
application actually cares.

Another thing is that you may need to send key
release after key press in order for the
application to trigger the F5/F2/F7 event. I'm not
sure what the scan codes for F5/F2/F7 releases
are, but think that they may be:

F5: 0xBF
F2: 0xBC
F7: 0xC1
 
M

Mel

Alexander said:
Another thing is that you may need to send key
release after key press in order for the
application to trigger the F5/F2/F7 event. I'm not
sure what the scan codes for F5/F2/F7 releases
are, but think that they may be:

F5: 0xBF
F2: 0xBC
F7: 0xC1

True. The key-release codes are the key-press codes (the "key numbers")
but with the high-order bit set.

Mel.
 
J

Justin Ezequiel

I'm not sure regarding the ASCII part. I think it
might need to be set to 0x00 for all functional
keys instead of 0x3F/0x3C/0x41, but probably no
application actually cares.

Another thing is that you may need to send key
release after key press in order for the
application to trigger the F5/F2/F7 event. I'm not
sure what the scan codes for F5/F2/F7 releases
are, but think that they may be:

F5: 0xBF
F2: 0xBC
F7: 0xC1

appreciate all the help.
unfortunately, my hard drive crashed and badly.
thus was unable to investigate this further.
as I was running out of time, we're now going for a reimplementation
of the legacy barcode program.
was fortunate to find an implementation that gives the same output
(we're testing thoroughly and we may have found a winner)

oh btw, it was a seagate 250GB drive for my dell laptop
may need to pay somebody to try to recover my personal files.
all work files are in version control so they're ok
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,145
Latest member
web3PRAgeency
Top