tags:

views:

98

answers:

1

Hi,

I would like to understand the values I get from read command in console. Are these outputs combinations of some keys?

F2   ^[OQ
F3   ^[OR
F4   ^[OS
ESC  ^[

My problem is that I use special 128 keys keyboard that is programmed for specific software. I need to send these "keys" into this software using code below. Don't be confused about the fact that I'm using Linux to read keyboard and in code below I use Win. I'm just trying to figure it out first on my Linux box.

import win32api, win32com.client

shell = win32com.client.Dispatch('WScript.Shell')
shell.AppActivate('Some Application Title')
shell.SendKeys('%fo')    # Alt+F, O
win32api.Sleep(100)

Thnx guys

+1  A: 

These are standard ANSI Escape Sequences. The "^[" is an CSI = Control Sequence Introducer (not a TV series).

See http://en.wikipedia.org/wiki/ANSI_escape_sequences or a similar source on ANSI Escape Sequences.

If you send such sequences to something that recognises them, you can cause the effect they imply, like clear screen, change colour or, indeed, act as if the F1 key was pressed. However, you do need a recipient which does handle them! (like an linux console) A simple File stream would just write the characters.

foo
I use a software that work with a specific keyboard (this one = http://www.tipro.si/images/product_midkm128a_big.jpg). I would like to have visual basic script or something like this to execute set of commands (keys pressed) on this software.With wscript.shell.sendkeys I was able to send characters into this software when I activated it (focused) with wscript.AppActivate('Some Application Title'). But now that I need to get it work with these special keys I got lost.
Mitja Felicijan
@Mitja Felicijan: The key codes in Windows are completely different than in Linux.
Dennis Williamson
Can you please explain why I got negative vote???
Mitja Felicijan
What you trying to do with the keycodes is non-standard, will work only under specific circumstances, and is thus generally considered a Bad Idea. I think that's why people may have given your question negative votes.
foo
The matter of portable keyboard input is, alas, still not quite solved. You can use "scancodes" (but not perfectly reliable for function keys and different layouts, plus kbhit is not portable); or you can use system-dependant functions - which are reliable, but not portable.
foo