Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » How to monitor key release event?
How to monitor key release event? [message #43049] Sun, 27 April 2014 01:01 Go to next message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello,

I am writing small platformer game with map editor Smile and I would like to handle key release events. Is there any way to do this in current version of U++?

What I have spied is that Ctrl::Key(dword key, int count) returns two events(X11):
Key: 130897, 1 // <- Key press event.
Key: 1179475, 1 // <- Key release event.


Of course I can handle it manually (by absolute key value), but it isn't elegant solution and probably it isn't platform independent.

Sincerely,
Klugier


U++ - one framework to rule them all.

[Updated on: Sun, 27 April 2014 01:04]

Report message to a moderator

Re: How to monitor key release event? [message #43051 is a reply to message #43049] Sun, 27 April 2014 10:14 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Klugier,

If I remember correctly, the K_KEYUP value should be what you're looking for. Just check if (key & K_KEYUP) is true or not. This an other flags used in key-codes are defined directly in CtrlCore.h.

Best regards,
Honza
Re: How to monitor key release event? [message #43052 is a reply to message #43051] Sun, 27 April 2014 15:33 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello Honza,

I have solved this problem. Thanks for tip Honza!

This is my code:
bool GameCtrl::Key(dword key, int count)
{
	if (key == K_RIGHT) {
		moveRight = true;
		return true;
	}
	else if (key == K_LEFT) {
		 moveLeft = true;
		return true;
	}
 	else if (key == K_SPACE) {
		jump = true;
		return true;
	}
	
	if (key & K_KEYUP) {
		dword keyUp = (key & ~K_KEYUP);
		
		if (keyUp == K_RIGHT) {
			moveRight = false;
			return true;
		}
		else if (keyUp == K_LEFT) {
			moveLeft = false;
			return true;
		}
		else if (keyUp == K_SPACE) {
			jump = false;
			return true;
		}
	}

	return false;
}


BTW, I think that U++ should offer following method "Ctrl::KeyUp(dword key, int count)". This will facilitate a few things...

Sincerely,
Klugier


U++ - one framework to rule them all.
Re: How to monitor key release event? [message #43973 is a reply to message #43052] Wed, 03 December 2014 16:07 Go to previous messageGo to next message
ManfredHerr is currently offline  ManfredHerr
Messages: 67
Registered: February 2013
Location: Germany
Member
My findings with KEY_UP are that it is NOT platform independent at all. First of all, it depends which key is pressed. The arrow keys are generating press and release events for you. But if you wait for key release events for aplha keys, e.g. 'a', then you wait forever in X11. But if you use GTK then a key release event comes up: KEY_UP + 'A'. Confused This means that the key symbols for press and release differ. I tried it with a "keyhook" in order to be at a lower level. No change.

The keyhooks are called in Ctrl::DispatchKey. But this obscure selection of keys, having a release event or not, already takes place in the platform dependent event processing.
I miss a hook to monitor every key on the keyboard with press and release.
Re: How to monitor key release event? [message #44243 is a reply to message #43973] Wed, 11 February 2015 09:19 Go to previous messageGo to next message
slashupp is currently offline  slashupp
Messages: 231
Registered: July 2009
Experienced Member
(delete this pls)

[Updated on: Wed, 22 February 2017 18:07]

Report message to a moderator

Re: How to monitor key release event? [message #44244 is a reply to message #43973] Wed, 11 February 2015 09:30 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
ManfredHerr wrote on Wed, 03 December 2014 16:07
My findings with KEY_UP are that it is NOT platform independent at all. First of all, it depends which key is pressed. The arrow keys are generating press and release events for you. But if you wait for key release events for aplha keys, e.g. 'a', then you wait forever in X11. But if you use GTK then a key release event comes up: KEY_UP + 'A'. Confused This means that the key symbols for press and release differ. I tried it with a "keyhook" in order to be at a lower level. No change.


You should not use ASCII (like 'A' + KEY_UP), but K_A|K_KEYUP.

Re: How to monitor key release event? [message #44251 is a reply to message #44243] Thu, 12 February 2015 20:58 Go to previous message
ManfredHerr is currently offline  ManfredHerr
Messages: 67
Registered: February 2013
Location: Germany
Member
Hi,
thank you for responding, I hardly can believe it! Twisted Evil
To make it clear: I don't want to have a key-logger! I just want to monitor the keyboard events then when my application has the input focus, with key press and key release info in the proper time. It seems that this is possible in a portable way despite of security issues. But how you do it in UPP?
In the meantime, I decided to go back to FLTK that provides better support on that, and claims to be portable too. Sorry.
My intent is, to assign a particular function to a set of keys of the keyboard, that can be invoked independent and in parallel, as long as the key is pressed. This function has nothing to do with text. To give an example: In former days there were games for two players. Each of the two controlled an object (his object), one of them with the cursor keys and the other with the keys 'A','W','D','X'. I see, that nowadays both players have a computer of their own and play over the network. So, that every one has his keyboard and cursor keys available. However, it's an example only.

Regards
Manfred
Previous Topic: Assist++ for STL
Next Topic: How does one create core and ctrllib as a dll?
Goto Forum:
  


Current Time: Thu Mar 28 11:45:16 CET 2024

Total time taken to generate the page: 0.01639 seconds