RE: [PHP-GTK] Key-release-event

From: Date: Fri, 28 Jan 2005 12:39:41 +0000
Subject: RE: [PHP-GTK] Key-release-event
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-5506@lists.php.net to get a copy of this message
Thanks for all your input. I've chosen for another solution though. This solution is perfect for robot-control/game-control things, because it also reads pressing more than one key on a low level. The downside is that it only works in Windows, as it involves an api-call to user32.dll. dl("php_w32api.dll"); Win32::RegisterFunction("int GetAsyncKeyState (long vKey) from user32.dll"); $keymapping = array("VK_RETURN" => 0x0D, "VK_SHIFT" => 0x10, "VK_CONTROL" => 0x11, "VK_LEFT" => 0x25, "VK_UP" => 0x26, "VK_RIGHT" => 0x27, "VK_DOWN" => 0x28, "A" => 0x41, "B" => 0x42, "C" => 0x43, "D" => 0x44, "E" => 0x45, "F" => 0x46, "G" => 0x47, "H" => 0x48, "I" => 0x49, "J" => 0x4A, "K" => 0x4B, "L" => 0x4C, "M" => 0x4D, "N" => 0x4E, "O" => 0x4F, "P" => 0x50, "Q" => 0x51, "R" => 0x52, "S" => 0x53, "T" => 0x54, "U" => 0x55, "V" => 0x54, "W" => 0x57, "X" => 0x58, "Y" => 0x59, "Z" => 0x5A ); function handleInput () { global $keymapping; if (Win32::GetAsyncKeyState($keymapping['VK_LEFT']) < 0) { echo "Move left!"; } if (Win32::GetAsyncKeyState($keymapping['VK_RIGHT']) < 0) { echo "Move right!"; } if (Win32::GetAsyncKeyState($keymapping['VK_UP']) < 0) { echo "Move up!"; } if (Win32::GetAsyncKeyState($keymapping['VK_DOWN']) < 0) { echo "Move down!"; } Gtk::timeout_add(100, 'handleInput'); } Gtk::timeout_add(100, 'handleInput'); Gtk:main(); -----Original Message----- From: Richard Lynch [mailto:ceo@l-i-e.com] Sent: donderdag 27 januari 2005 23:22 To: Emiel Mols Cc: php-gtk-general@lists.php.net Subject: Re: [PHP-GTK] Key-release-event Emiel Mols wrote: > I understand :), but I'm trying to build an application which controls > some > robotics. Since I want the robot to stop moving when I stop pressing a > key, > I need a key-release-event to do this. In the Control panel I can't turn > this 'feature' of. Furthermore, the key-release-event occurs directly > after > the key-press-event, so it's quite useless. In the key-released function, record the time and start a timer for X seconds. In your key-pressed function, check the time since the recorded. If it's < X, they are still holding the key down, so kill the timer previously set in key-released. Eventually, a timer will survive because they stopped holding the key, and you can use THAT to fire your robot stopping. You'll probably want to bind the key pressed and whatnot into the timers, but you get the idea. -- Like Music? http://l-i-e.com/artists.htm -- PHP-GTK General Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.gtk.general (#5506) next »