473,671 Members | 2,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I know both the Key c and Ctrl on the keyboard are pressed?

Hi;
How can I know the Key c and Ctrl on the keyboard are pressed? Or how
to let the program press the

key Ctrl+c automatically? I just want to use python to develop a
script program.
gear

Jan 30 '07 #1
4 2297

ti***********@t om.com wrote:
Hi;
How can I know the Key c and Ctrl on the keyboard are pressed? Or how
to let the program press the

key Ctrl+c automatically? I just want to use python to develop a
script program.
gear
depends on where you got your input from and what do you exactly want

eg:
in a gui app you get input events from the gui toolkit (wx, gtk, sdl/
pygame...)
in a console app if you use curses lib then you can use getch() oslt

if you want a general solution to get input key events in a simple
script then you cannot do that.

however Ctrl+C is a special key combination: running python in a unix
terminal it raises KeyboardInterru pt exception, imho in a windows cmd
promt it raises SystemExit

so you can emulate those by using:
raise KeyboardInterru pt
or
raise SystemExit

hope this helps

Jan 30 '07 #2
On 30 Jan 2007 05:44:40 -0800, Szabolcs Nagy <ns*******@gmai l.comwrote:
however Ctrl+C is a special key combination: running python in a unix
terminal it raises KeyboardInterru pt exception, imho in a windows cmd
promt it raises SystemExit
No it is KeyboardInterru pt in Windows too.

--
mvh Björn
Jan 30 '07 #3
"Szabolcs Nagy" <ns*******@gmai l.comwrote:
however Ctrl+C is a special key combination: running python in a
unix
terminal it raises KeyboardInterru pt exception, imho in a windows
cmd
promt it raises SystemExit
Your humble opinion is wrong.

Under windows Ctrl-C raises KeyboardInterru pt just as it does under
linux. Ctrl-break by default terminates the program (without invoking
Python's usual cleanup), but you can override that behaviour by
registering a different signal handler.

e.g.

import signal
signal.signal(s ignal.SIGBREAK,
signal.default_ int_handler)

will make Ctrl-break raise KeyboardInterru pt just like Ctrl-C.

Jan 30 '07 #4
En Tue, 30 Jan 2007 05:50:29 -0300, <ti***********@ tom.comescribió :
How can I know the Key c and Ctrl on the keyboard are pressed? Or how
to let the program press the

key Ctrl+c automatically? I just want to use python to develop a
script program.
gear
If you are on Windows and want to trap the Ctrl-C combination, just catch
the KeyboardInterru pt exception:

--- cut ---
from time import sleep

while 1:
try: sleep(1)
except KeyboardInterru pt: print "Ctrl-C pressed"
--- cut ---

--
Gabriel Genellina

Jan 30 '07 #5

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

Similar topics

4
13974
by: Scott | last post by:
I am using a TCPIP connection to communicate over port 23 (telnet) to a server, and I am having to mimic normal command line interface you owuld see in a telnet session (i.e. I have to write to this socket just like you would enter things on the keyboard if you telneted to this server). In a normal telnet session you can enter some commands which take a long time to complete, and they run in the background and you get the command line...
3
34333
by: Mr. x | last post by:
Hello, I want to capture the event when the <ctrl> key is pressed. How can I do that ? Thanks :)
10
23526
by: chirs | last post by:
I have a code to disable ctrl-v (paste) on the 2nd box. The problem is that when I type ctrl-v, the text shows, then disappear after I release ctrl-v. How can I make it not to show in the box. In VB, I can set keyascii=0 to kill the input. Is there a similar way to do it in JavaScript? Thanks a lot. <HTML><head></head><body> <form name="myForm"> Password: <input type="text"><br> Comfirm: <input type="text" name="myText"
8
2943
by: MLH | last post by:
I use a mouse-down procedure to trap right mouse clicks and CTRL-Right mouse clicks. Running the procedure must put honey or some other sticky substance into my keyboard because subsequent RightMouseClicks run as if they were CTRL-RightMouseClicks I have to close the form and reopen it to clear this behavior. Then, after the first CTRL-RightMouseClick, it starts all over again.
1
2629
by: Pedro Graca | last post by:
Well ... I've been using Windows for a long time before I switched to Linux. I'm very used to type CTRL-ALT-DEL everytime I'm leaving my computer or arriving to it. It's hapenned _twice_ (in the last six months or so) for my Linux box. I want to be able to reboot my machine with CTRL-ALT-DEL, but I don't want to do it by mistake. So, I noticed /etc/inittab has these lines
3
43992
by: Stefan | last post by:
Hy, i have an app and i must disable this combination: ALT+F4; CTRL+ALT+DEL; CTRL+ESC;ALT+TAB like this: i find something on Internet and i can block ALT+F4 protected override System.Boolean ProcessCmdKey(ref System.Windows.Forms.Message msg,System.Windows.Forms.Keys keyData)
8
10225
by: Christian Blackburn | last post by:
Hi Gang, In most programs Ctrl+A is Select All. I'm inclined to use the most common keyboard shortcuts, whenever possible. What are the names of some programs that have a key assigned for select none and what key do they use? I think I'm going to go with Ctrl+ (Minus Sign), but I'm interested in people's suggestions. Thanks,
17
7411
by: Kbalz | last post by:
I'm developing a Wizard type program, and I'm flipping between steps by using a TabControl.. buttons on each tabPage move to the next or previous tabPage. When I press CTRL+Tab however, the tabControl begins to cycle through the tabPages, just as it does in Visual Studio, IE7 etc.. any tabbed program. I need this blocked.
1
3059
by: phcmi | last post by:
Within a mousedown event, can you please show a code sample of how to ascertain whether the CTRL and/or ALT and/or SHIFT keyboard key is pressed? Thank you
0
8485
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
8403
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,...
1
8605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8677
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...
1
6238
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4417
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1816
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.