New Posts  All Forums:Forum Nav:

Python question

post #1 of 28
Thread Starter 
I'm still quite a noob to Python, and am completely stumped by this.
Code:
def keyStroke():
    keyValue = msvcrt.getch()
    if keyValue == ("/r"):
        print ("Pressed Enter!")

x=1
while x!=2:
    keyStroke()


I cannot find what is wrong with that.

Yes, i've imported msvcrt.
The application will open, and do absolutely nothing at all. Will not register anything.

??
Edited by White Fire - 8/2/12 at 12:59pm
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
post #2 of 28
I've never used Python on Windows but what happens if you do
Code:
while(True):
    print (msvcrt.getch())

If that doesn't work I'd assume the problem lays somewhere else in you program.
buka
(17 items)
 
  
Reply
buka
(17 items)
 
  
Reply
post #3 of 28
Thread Starter 
Quote:
Originally Posted by poroboszcz View Post

I've never used Python on Windows but what happens if you do
Code:
while(True):
    print (msvcrt.getch())

If that doesn't work I'd assume the problem lays somewhere else in you program.
That did work to return the keystroke, but my real problem lies in the fact I cannot do anything with it.

If statements are not wanting to work
Code:
def keyStroke():
    key = msvcrt.getch()
    if key == ("a"):
        print ("A!")
        input("")

while(True):
    keyStroke()

That right there does absolutely nothing.
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
post #4 of 28
I don't know. Run this code and tell me what you get:
Code:
def keyStroke():
    key = msvcrt.getch()
    c = 'a'
    print key + "==" + c "?\n"
    print key == c

while(True):
    keyStroke()
buka
(17 items)
 
  
Reply
buka
(17 items)
 
  
Reply
post #5 of 28
Thread Starter 
Quote:
Originally Posted by poroboszcz View Post

I don't know. Run this code and tell me what you get:
Code:
def keyStroke():
    key = msvcrt.getch()
    c = 'a'
    print key + "==" + c "?\n"
    print key == c

while(True):
    keyStroke()
Errors sad-smiley-002.gif
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
post #6 of 28
If it's python 3 add brackets around arguments following print statements and if you still get errors replace pluses with commas. If that still doesn't work show me the errors.
buka
(17 items)
 
  
Reply
buka
(17 items)
 
  
Reply
post #7 of 28
Thread Starter 



EDIT: I see I missed the () on the msvcrt.getch, hang on.
Same error with the ()
Edited by White Fire - 8/2/12 at 5:41pm
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
post #8 of 28
I meant single brackets around all arguments: print (key, "==", c, "?\n") and print (key==c) smile.gif
buka
(17 items)
 
  
Reply
buka
(17 items)
 
  
Reply
post #9 of 28
Thread Starter 
Quote:
Originally Posted by poroboszcz View Post

I meant single brackets around all arguments: print (key, "==", c, "?\n") and print (key==c) smile.gif

Oh, sorry redface.gif

OK, fixed it like you said.

It returns everything its supposed to, but even pressing A returns false -.-
Edited by White Fire - 8/2/12 at 5:45pm
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
Red Thunder
(19 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Fatal1ty Z68 Pro3 Gen3 Diamond Multimedia HD 5970 G.Skill Ripjaws X 8GB 
Hard DriveHard DriveOptical DriveCooling
OCZ Solid 3 60GB Seagate Barracuda 7200.9 160GB Lite-On iHAS424 Sunbeam Twister 120 
OSMonitorKeyboardPower
Windows 7 Ultimate 64-bit Samsung SyncMaster E1920X Logitech K120 Corsair GS700 
CaseMouseMouse PadAudio
NZXT Phantom Razer Naga None Realtek ALC892 
OtherOtherOther
Behringer Xenyx 502 Lepai LP-2020A+ Dayton Audio B652 
  hide details  
Reply
post #10 of 28
So it prints:
Code:
a == a?
False

?
buka
(17 items)
 
  
Reply
buka
(17 items)
 
  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming