Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › C++ Polling keyboard keys
New Posts  All Forums:Forum Nav:

C++ Polling keyboard keys

post #1 of 9
Thread Starter 
Hey, I have written a simple test of curses (PDcurses) keyboard input, it works but when I hold 2 keys down at the same time I only get the most recent key press. How would I monitor or poll only one key at a time and check if they are being pressed? Hopefully this can be done with curses but I'm afraid I might have to pick a input library like OIS or DirectInput, I think GLUT can also do it.

This is for a console based game.
X-Caliber
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Quad Q8300 @3.0 Ghz Gigabyte EP43 UD3L ATI Radeon HD3850 512MB 800/950 4x1 GB 800 mhz DDR2 (Dual Channel) 
Hard DriveOptical DriveOSMonitor
160 Hitachi HDD LG Super-Multi Drive with SecurDisc Windows 7 - Ultimate (x86) Samsung SyncMaster 2043SWX 20" 1600x900 
KeyboardPowerCaseMouse
Logitech G15 Gaming Keyboard rev. 2 460 watt Coolermaster Coolermaster Elite Razer Deathadder 
Mouse Pad
Steelseries QcK 
  hide details  
Reply
X-Caliber
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Quad Q8300 @3.0 Ghz Gigabyte EP43 UD3L ATI Radeon HD3850 512MB 800/950 4x1 GB 800 mhz DDR2 (Dual Channel) 
Hard DriveOptical DriveOSMonitor
160 Hitachi HDD LG Super-Multi Drive with SecurDisc Windows 7 - Ultimate (x86) Samsung SyncMaster 2043SWX 20" 1600x900 
KeyboardPowerCaseMouse
Logitech G15 Gaming Keyboard rev. 2 460 watt Coolermaster Coolermaster Elite Razer Deathadder 
Mouse Pad
Steelseries QcK 
  hide details  
Reply
post #2 of 9
Quote:
Originally Posted by Darkknight512;13001131 
Hey, I have written a simple test of curses (PDcurses) keyboard input, it works but when I hold 2 keys down at the same time I only get the most recent key press. How would I monitor or poll only one key at a time and check if they are being pressed? Hopefully this can be done with curses but I'm afraid I might have to pick a input library like OIS or DirectInput, I think GLUT can also do it.

This is for a console based game.

You need raw access to the keyboard, and curses will not provide this.
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
post #3 of 9
Thread Starter 
Quote:
Originally Posted by error10;13001670 
You need raw access to the keyboard, and curses will not provide this.

Do you know of a library that would allow it? I'm looking for a library that will let me check from my program, if the key is being held down or not.
X-Caliber
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Quad Q8300 @3.0 Ghz Gigabyte EP43 UD3L ATI Radeon HD3850 512MB 800/950 4x1 GB 800 mhz DDR2 (Dual Channel) 
Hard DriveOptical DriveOSMonitor
160 Hitachi HDD LG Super-Multi Drive with SecurDisc Windows 7 - Ultimate (x86) Samsung SyncMaster 2043SWX 20" 1600x900 
KeyboardPowerCaseMouse
Logitech G15 Gaming Keyboard rev. 2 460 watt Coolermaster Coolermaster Elite Razer Deathadder 
Mouse Pad
Steelseries QcK 
  hide details  
Reply
X-Caliber
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Quad Q8300 @3.0 Ghz Gigabyte EP43 UD3L ATI Radeon HD3850 512MB 800/950 4x1 GB 800 mhz DDR2 (Dual Channel) 
Hard DriveOptical DriveOSMonitor
160 Hitachi HDD LG Super-Multi Drive with SecurDisc Windows 7 - Ultimate (x86) Samsung SyncMaster 2043SWX 20" 1600x900 
KeyboardPowerCaseMouse
Logitech G15 Gaming Keyboard rev. 2 460 watt Coolermaster Coolermaster Elite Razer Deathadder 
Mouse Pad
Steelseries QcK 
  hide details  
Reply
post #4 of 9
Quote:
Originally Posted by Darkknight512;13002201 
Do you know of a library that would allow it? I'm looking for a library that will let me check from my program, if the key is being held down or not.

GLUT would be just fine for this. Of course you would have to be running in a windowing system, and there goes the whole curses thing out the window (no pun intended). Time to redesign your app.
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
post #5 of 9
Thread Starter 
Alright thanks, I'm currently just testing out these libraries by making a basic pong game. What I intend to do after this is to write a console based text RPG engine that will somehow be very easily modifiable, so far I have done some research in XML to do that.

I know it is possible to read when a button is down or up with the windows libraries but I am trying to avoid tying myself to an OS is possible. This is pretty much my first large project and will probably never need to be ported but I guess it is better to make sure it is portable if it needs to be.

Are there any other tings you could think of that would work well for me?
X-Caliber
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Quad Q8300 @3.0 Ghz Gigabyte EP43 UD3L ATI Radeon HD3850 512MB 800/950 4x1 GB 800 mhz DDR2 (Dual Channel) 
Hard DriveOptical DriveOSMonitor
160 Hitachi HDD LG Super-Multi Drive with SecurDisc Windows 7 - Ultimate (x86) Samsung SyncMaster 2043SWX 20" 1600x900 
KeyboardPowerCaseMouse
Logitech G15 Gaming Keyboard rev. 2 460 watt Coolermaster Coolermaster Elite Razer Deathadder 
Mouse Pad
Steelseries QcK 
  hide details  
Reply
X-Caliber
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Quad Q8300 @3.0 Ghz Gigabyte EP43 UD3L ATI Radeon HD3850 512MB 800/950 4x1 GB 800 mhz DDR2 (Dual Channel) 
Hard DriveOptical DriveOSMonitor
160 Hitachi HDD LG Super-Multi Drive with SecurDisc Windows 7 - Ultimate (x86) Samsung SyncMaster 2043SWX 20" 1600x900 
KeyboardPowerCaseMouse
Logitech G15 Gaming Keyboard rev. 2 460 watt Coolermaster Coolermaster Elite Razer Deathadder 
Mouse Pad
Steelseries QcK 
  hide details  
Reply
post #6 of 9
You could try using SDL (Simple DirectMedia Layer, cross platform library for making games). Its worked well enough for me in the past.
post #7 of 9
Quote:
Originally Posted by ShamrockMan;13010163 
You could try using SDL (Simple DirectMedia Layer, cross platform library for making games). Its worked well enough for me in the past.

Seconded. SDL wraps up everything for you.

As for it being a console game, if you really need raw keyboard access, you can't run it on a console; it simply does not provide any way to gain raw keyboard access. You will have to make it a fully graphical application.
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
post #8 of 9
Quote:
Originally Posted by Darkknight512;13001131 
Hey, I have written a simple test of curses (PDcurses) keyboard input, it works but when I hold 2 keys down at the same time I only get the most recent key press. How would I monitor or poll only one key at a time and check if they are being pressed? Hopefully this can be done with curses but I'm afraid I might have to pick a input library like OIS or DirectInput, I think GLUT can also do it.

This is for a console based game.

You mean something like GetKeyState?
My giant
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6600 lapped Asus P5n32-E 680i GeForce 9800GT 512MB 2x1GB (unused ATM) & 2x2Gb Corsair XMS2 PC6400 
Hard DriveOSMonitorPower
WDJS SATA-II 160GB + WD80GB + WDAAKS Raid0 320GB Aperature FSII 19" LCD Apevia DarkSide 600W 
Case
NZXT Zero 
  hide details  
Reply
My giant
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6600 lapped Asus P5n32-E 680i GeForce 9800GT 512MB 2x1GB (unused ATM) & 2x2Gb Corsair XMS2 PC6400 
Hard DriveOSMonitorPower
WDJS SATA-II 160GB + WD80GB + WDAAKS Raid0 320GB Aperature FSII 19" LCD Apevia DarkSide 600W 
Case
NZXT Zero 
  hide details  
Reply
post #9 of 9
Thread Starter 
Quote:
Originally Posted by Kirmie;13013804 
You mean something like GetKeyState?

That's pretty much what I am looking for but that is in Windows.h and I don't want to tie myself to and operating system, I'm here to look for an alternative to GetKeyState.
X-Caliber
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Quad Q8300 @3.0 Ghz Gigabyte EP43 UD3L ATI Radeon HD3850 512MB 800/950 4x1 GB 800 mhz DDR2 (Dual Channel) 
Hard DriveOptical DriveOSMonitor
160 Hitachi HDD LG Super-Multi Drive with SecurDisc Windows 7 - Ultimate (x86) Samsung SyncMaster 2043SWX 20" 1600x900 
KeyboardPowerCaseMouse
Logitech G15 Gaming Keyboard rev. 2 460 watt Coolermaster Coolermaster Elite Razer Deathadder 
Mouse Pad
Steelseries QcK 
  hide details  
Reply
X-Caliber
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Quad Q8300 @3.0 Ghz Gigabyte EP43 UD3L ATI Radeon HD3850 512MB 800/950 4x1 GB 800 mhz DDR2 (Dual Channel) 
Hard DriveOptical DriveOSMonitor
160 Hitachi HDD LG Super-Multi Drive with SecurDisc Windows 7 - Ultimate (x86) Samsung SyncMaster 2043SWX 20" 1600x900 
KeyboardPowerCaseMouse
Logitech G15 Gaming Keyboard rev. 2 460 watt Coolermaster Coolermaster Elite Razer Deathadder 
Mouse Pad
Steelseries QcK 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › C++ Polling keyboard keys