473,769 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Curses & Keypress

Now that I have gotoxy() down for moving the cursor around, I want that
to be a result of keypresses (namely from the numpad -- 7 = NorthWest,
8 = North, 9 = NE, etc...). I have little clue how to do this. After
searching google, I've come upon this; include:

import curses

in the header. However, I've found various methods of actually reading
the keyboard press (getch(), raw_input, etc.). What is the best method
to use for reading keypress, so I can have something like:

if (keypressvariab le == 'numpad7'):
WConio.gotoxy(x-1,y+1)

etc...

Thanks.

Nov 11 '05 #1
1 3732
On 2005-11-11, al***********@g mail.com <al***********@ gmail.com> wrote:
Now that I have gotoxy() down for moving the cursor around, I want that
to be a result of keypresses (namely from the numpad -- 7 = NorthWest,
8 = North, 9 = NE, etc...). I have little clue how to do this. After
searching google, I've come upon this; include:

import curses

in the header. However, I've found various methods of actually reading
the keyboard press (getch(), raw_input, etc.). What is the best method
to use for reading keypress, so I can have something like:

if (keypressvariab le == 'numpad7'):
WConio.gotoxy(x-1,y+1)



Here is a little snip that shows how I do this:
#
import curses

class TestScreen:
def __init__(self, scr):
self.scr = scr
self.scr.move(1 0, 5)
self.scr.addstr ('Press q to QUIT', curses.A_BOLD)
def loop(self):
k = None
while k != 'q':
k = self.scr.getkey ()
try:
o = ord(k)
except:
o = '????'
#Error.elog('te st:', k, o)

def test_keys(scr):
screen = TestScreen(scr)
screen.loop()

if __name__ == '__main__':
curses.wrapper( test_keys)
#

Not on windows, though. So I do not know if this
will work for you at all.

The .elog thing is a function I wrote for testing
curses apps. Since the console is busy, you can't
usefully print to stdout. So .elog just feeds its
arguments to a log file.

I found the trickiest part is that the keyboard
scan codes are all over the place. Two systems
that are identical in every other way might give
two different results when pressing a key.
Nov 11 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1773
by: Matthew Alton | last post by:
The appended program freaks python 2.2 & 2.3 completely out. To reproduce the wierdness: i) copy the source to a file called consarn.py ii) $ python consarn.py; iii) the program is now doing a getch(); iv) hit a key; v) the program locks up, the interptreter is now munching on the CPU; vi) kill the interpreter from another shell; vii) scratch head and wonder why neither of the mutually exclusive clauses in the _io() member function...
0
1876
by: Matt Garman | last post by:
I'd like to write a class or module in python that allows me to do on-the-fly color changing in the curses module. I'm thinking about something along the lines of this: addstr(y, x, 'hello', brightyellow, blue) The module would automatically interpret the above as curses.init_pair(i, curses.COLOR_YELLOW, curses.COLOR_BLUE)
0
2401
by: Brano Zarnovican | last post by:
Hi ! I'd like to init curses and still have working Python interactive command line. I found that you can replace stdin/stdout/stderr like this: #!/usr/bin/python -i import curses import sys
1
3226
by: ray well | last post by:
hi, i need to preview the keys in my app in order to process F1-F10. i set keypreview of my form to true, and it does capture the keystrokes from all over the forms controls which i then process. i found 2 puzzeling exception: if the user is inside the text box of a ComboBox, the keystrokes aren't captured in the form's keypress event. i have to separately capture the
0
1553
by: Casey Bralla | last post by:
My problem was caused by a getch() function which paused, waiting for the character. Live and learn. <sigh> For some reason, I can't get curses to refresh the screen. Can someone offer a suggestion to try to debug this? Here is my python code snippet: stdscr=curses.initscr() curses.noecho()
1
3696
by: Jerry Fleming | last post by:
Hi, I have wrote a game with python curses. The problem is that I want to confirm before quitting, while my implementation doesn't seem to work. Anyone can help me? #!/usr/bin/python # # Brick & Ball in Python # by Jerry Fleming <jerryfleming@etang.com>
0
1058
by: John Hunter | last post by:
I have a curses app that is displaying real time data. I would like to bind certain keys to certain functions, but do not want to block waiting for c = screen.getch() Is it possible to register callbacks with curses, something like screen.register('keypress', myfunc)
5
6330
by: 7stud | last post by:
I can't see to get any y, x coordinates to work with curses. Here is an example: import curses def my_program(screen): while True: ch = screen.getch() if ch == ord("q"): break
4
4869
by: Zoubidoo | last post by:
Many applications require a high-speed interface such as supermarket checkouts, busy points of sale, doctors' surgeries etc. The problem with graphical interfaces is that they are too slow for this kind of environment. Imagine a web interface at the supermarket checkout - just not viable. Would it be possible to build a text-based interface *within* a normal browser window - like curses? Keypresses would be interpreted by javascript...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.