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 » Developing U++ » UppHub » New functions to SysInfo
New functions to SysInfo [message #19427] Wed, 03 December 2008 09:57 Go to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello all

After this first group of functions I want to include in January functions to handle with:

- Change or retrieve window size and position

- Screen capture: Certain window or all the screen
--- Image
--- Video

- Simulate user input
--- Mouse move and click without a mouse
--- Keyboard clicking without a keyboard

Best regards
Koldo


Best regards
Iñaki
Re: New functions to SysInfo [message #19437 is a reply to message #19427] Wed, 03 December 2008 21:27 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
koldo wrote on Wed, 03 December 2008 09:57

Hello all

After this first group of functions I want to include in January functions to handle with:

- Change or retrieve window size and position

- Screen capture: Certain window or all the screen
--- Image
--- Video

- Simulate user input
--- Mouse move and click without a mouse
--- Keyboard clicking without a keyboard

Best regards
Koldo


Wonderfull!
These are the functions that I dream to have. I'm ready to test it.

Luigi
Re: New functions to SysInfo [message #20527 is a reply to message #19427] Sun, 22 March 2009 10:24 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

koldo wrote on Wed, 03 December 2008 11:57

- Screen capture: Certain window or all the screen
--- Image
Could you please tell if there are this function in SysInfo, and if it is - how is it called?
Re: New functions to SysInfo [message #20568 is a reply to message #19427] Mon, 23 March 2009 18:44 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Mindtraveller

They are not implemented.

Let me one week and they will be in SysInfo.

Best regards
Koldo


Best regards
Iñaki
Re: New functions to SysInfo [message #20575 is a reply to message #19427] Tue, 24 March 2009 09:19 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

koldo wrote on Wed, 03 December 2008 10:57

Hello all

After this first group of functions I want to include in January functions to handle with:

- Change or retrieve window size and position

- Screen capture: Certain window or all the screen
--- Image
--- Video

- Simulate user input
--- Mouse move and click without a mouse
--- Keyboard clicking without a keyboard

Best regards
Koldo

NICE FUNCTION! I'LL BE GLAD TO TEST IT!
Re: New functions to SysInfo [message #20731 is a reply to message #19427] Thu, 02 April 2009 12:01 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello all

I will insert these functions in Bazaar this afternoon

void Mouse_LeftClick();
void Mouse_MiddleClick();
void Mouse_RightClick();
void Mouse_LeftDblClick();
void Mouse_MiddleDblClick();
void Mouse_RightDblClick();

void Mouse_SetPos(long x, long y, long windowId);
void Mouse_GetPos(long &x, long &y);

void Keyb_SendKeys(String text, long finalDelay = 100, long delayBetweenKeys = 50);

void Window_GetRect(long windowId, long &left, long &top, long &right, long &bottom);
void Window_SetRect(long windowId, long left, long top, long right, long bottom);

bool Window_SaveCapture(long windowId, const char *fileName);

Usually I prefer to wait an release things for Linux and Windows but this time I have few time so I have only done them for Windows.

Tested in MinGW and MSC9 in XP.

All feedback is acknowledged.

Best regards
Koldo


Best regards
Iñaki
Re: New functions to SysInfo [message #21193 is a reply to message #20731] Fri, 08 May 2009 16:03 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Hello Koldo!

Do you know how can I handle global shortcut in U++?

I want to realized global shortcut for Google Translation!

Somebody know how can I handle a global shortcut for win32 and Linux?

Thanks in advance!
Re: New functions to SysInfo [message #21202 is a reply to message #21193] Sat, 09 May 2009 09:15 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello tojocky

As I did not know about that I have taken this definition from Gnome, but seems to be useful everywhere:
Quote:

Global shortcut keys enable you to use the keyboard to perform tasks related to your desktop, rather than tasks on the currently selected window or application


It seems to be related to the desktop system (gnome, kde)

Best regards
Koldo


Best regards
Iñaki
Re: New functions to SysInfo [message #21203 is a reply to message #21202] Sat, 09 May 2009 11:09 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

koldo wrote on Sat, 09 May 2009 10:15

Hello tojocky

As I did not know about that I have taken this definition from Gnome, but seems to be useful everywhere:
Quote:

Global shortcut keys enable you to use the keyboard to perform tasks related to your desktop, rather than tasks on the currently selected window or application


It seems to be related to the desktop system (gnome, kde)

Best regards
Koldo


I need this handle in windows too!
Re: New functions to SysInfo [message #21204 is a reply to message #21203] Sat, 09 May 2009 15:15 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello tojocky

I think I understand you: when your program is running although hidden in the tray you want to open it by clicking some keys like the Ctrl+Ctrl used for Google Desktop, isn't it?

Best regards
Koldo


Best regards
Iñaki
Re: New functions to SysInfo [message #21205 is a reply to message #21204] Sat, 09 May 2009 16:42 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello tojocky

If that is your situation
koldo wrote on Sat, 09 May 2009 15:15

I think I understand you: when your program is running although hidden in the tray you want to open it by clicking some keys like the Ctrl+Ctrl used for Google Desktop, isn't it?


you can do this in Windows:

To monitor keys, for example left Control key, you have to call GetKeyState().

This function answers you if the key is pressed and if it is toggled (this serves too for keys that are not the Caps-Lock!).

A sample:

	char k = GetKeyState(VK_LCONTROL);
	if (k & 1)
		puts("Toggled");
	if (k & 128)
		puts("Pressed");

This works although your program is not focused, and does not affect to the normal keyboard use, I mean, you will not steal keys to anybody.

When your program is in the tray you can enter it in a loop that checks every 100 ms the Ctrl toggle state. If you detects toggle two times in less than 200 ms, voilá!

Best regards
Koldo




Best regards
Iñaki
Re: New functions to SysInfo [message #21212 is a reply to message #21205] Sat, 09 May 2009 22:01 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Hello Koldo!

Yes, You understand me correct!

I want to handle the shortcut key when the GoogleTranslator is running (is in tray or opened main window).

For the first I would like to handle the shortcut [Ctrl]+[C]+[C] or [Ctrl]+[Ins]+[Ins] . With this handle I can read from buffer the copied text and translate this.

If I'm wrong, please correct me.

If you can give me a simple example about this, i will be glad!


Thank you Koldo!
Re: New functions to SysInfo [message #21219 is a reply to message #21212] Sun, 10 May 2009 08:50 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
tojocky wrote on Sat, 09 May 2009 22:01

Hello Koldo!

Yes, You understand me correct!

I want to handle the shortcut key when the GoogleTranslator is running (is in tray or opened main window).

For the first I would like to handle the shortcut [Ctrl]+[C]+[C] or [Ctrl]+[Ins]+[Ins] . With this handle I can read from buffer the copied text and translate this.

If I'm wrong, please correct me.

If you can give me a simple example about this, i will be glad!


Thank you Koldo!


Hello tojocky

You can use this
CONSOLE_APP_MAIN
{
	TimeStop t;
	int t_ctrl_l, t_ctrl_r;
	
	t_ctrl_r = t_ctrl_l = 0;
	while (true) {
		char ctrl_l = (char)GetKeyState(VK_LCONTROL);
		if (ctrl_l & 128)		// Left Ctrl pressed
			t_ctrl_l = t.Elapsed();
		char ctrl_r = (char)GetKeyState(VK_RCONTROL);			
		if (ctrl_r & 128)		// Right Ctrl pressed
			t_ctrl_r = t.Elapsed();			
		if (t_ctrl_r - t_ctrl_l < 300 && t_ctrl_r - t_ctrl_l > 0) {
			puts("Voila");
			t_ctrl_r = t_ctrl_l = 0; 	
		}

		Sleep(100);
	}


This will out a "Voila" when a Ctrl left and a Ctrl right are pressed.

For a Gui application remove the while loop and the Sleep() and put this in a Timer function.

Best regards
Koldo


Best regards
Iñaki
Re: New functions to SysInfo [message #21222 is a reply to message #21212] Sun, 10 May 2009 09:23 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

tojocky wrote on Sun, 10 May 2009 00:01

I want to handle the shortcut key when the GoogleTranslator is running (is in tray or opened main window).
Testing keyboard with timeout is good, but there are two drawbacks:
- Pushing keyboard could possibly fit into "sleep" period
- If you make this sleep period too short (less than 200 msec) this will possibly degrade overall system performance, especially on older machines.

There is a way to check these keys in a less brute way. It is called keyboard hook. On short, you request operating system to install key sequence and message. When user presses these key sequence in ANY application, OS automatically sends hook-installed message to you main window.

That`s the way it`s done in Windows:
http://www.codeguru.com/cpp/w-p/system/keyboard/article.php/ c5699

I don`t know really know if there is a common solution for setting hooks in POSIX systems this way easy. But what I found is the xbindkeys application:
http://hocwp.free.fr/xbindkeys/xbindkeys.html
I don`t know if it works properly and exist between many *nix window managers (I do personally use xfce and fluxbox). Hope this helps.
Re: New functions to SysInfo [message #21251 is a reply to message #21222] Sun, 10 May 2009 22:08 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Mindtraveller

I am almost agree with you but I would like to clarify a little bit:

- In windows

Installing a keyboard hook is a good solution as there is no possibility to lose a key. The reason is because the OS will call your function every time an user press a key


- In Posix

xbindkeys seems to be the solution. But it does not do miracles. The core of the program is in an infinite loop beginning with:
  	while (True) {
   		while(!XPending(d)) {
   			...
	  		usleep(SLEEP_TIME*1000);
		}
...


where SLEEP_TIME is 100, so it checks every tenth of second if something has happened.

Install a keyboard listener is never cheap, but it is useful so at least they have to do things reliabily and fast.


Best regards
Koldo



Best regards
Iñaki
Re: New functions to SysInfo [message #21252 is a reply to message #21251] Sun, 10 May 2009 22:50 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Koldo, if you know better solution for POSIX - please tell. IMO xbindkeys is better than local cycle at least because it will make ONE cycle for ALL executed programs, and even if you run a number of programs based on U++/xbindkeys, you`ll get only ONE cycle. But I`m not really shure if it is portable solution. So one needs to investigate which window managers / distributives have this utility and which are not.
Re: New functions to SysInfo [message #21282 is a reply to message #21252] Mon, 11 May 2009 15:53 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Mindtraveller wrote on Sun, 10 May 2009 23:50

Koldo, if you know better solution for POSIX - please tell. IMO xbindkeys is better than local cycle at least because it will make ONE cycle for ALL executed programs, and even if you run a number of programs based on U++/xbindkeys, you`ll get only ONE cycle. But I`m not really shure if it is portable solution. So one needs to investigate which window managers / distributives have this utility and which are not.


Someone knows what uses native Linux and MacOS.
Is possible to add this in U++?
Re: New functions to SysInfo [message #21333 is a reply to message #21219] Wed, 13 May 2009 17:12 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

koldo wrote on Sun, 10 May 2009 09:50

tojocky wrote on Sat, 09 May 2009 22:01

Hello Koldo!

Yes, You understand me correct!

I want to handle the shortcut key when the GoogleTranslator is running (is in tray or opened main window).

For the first I would like to handle the shortcut [Ctrl]+[C]+[C] or [Ctrl]+[Ins]+[Ins] . With this handle I can read from buffer the copied text and translate this.

If I'm wrong, please correct me.

If you can give me a simple example about this, i will be glad!


Thank you Koldo!


Hello tojocky

You can use this
CONSOLE_APP_MAIN
{
	TimeStop t;
	int t_ctrl_l, t_ctrl_r;
	
	t_ctrl_r = t_ctrl_l = 0;
	while (true) {
		char ctrl_l = (char)GetKeyState(VK_LCONTROL);
		if (ctrl_l & 128)		// Left Ctrl pressed
			t_ctrl_l = t.Elapsed();
		char ctrl_r = (char)GetKeyState(VK_RCONTROL);			
		if (ctrl_r & 128)		// Right Ctrl pressed
			t_ctrl_r = t.Elapsed();			
		if (t_ctrl_r - t_ctrl_l < 300 && t_ctrl_r - t_ctrl_l > 0) {
			puts("Voila");
			t_ctrl_r = t_ctrl_l = 0; 	
		}

		Sleep(100);
	}


This will out a "Voila" when a Ctrl left and a Ctrl right are pressed.

For a Gui application remove the while loop and the Sleep() and put this in a Timer function.

Best regards
Koldo


Hello Koldo,

Can you emulate shortcut event [Ctrl]+[C]+[C] in your example?

Sorry for incompetence, but in this event I'm new!
Re: New functions to SysInfo [message #21602 is a reply to message #19427] Thu, 28 May 2009 23:29 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello all

I have fully documented SysInfo bazaar package.

As it is my first experience using Topic++, please check it and tell me if it is ok for you.

Now I am documenting OfficeAutomation following the same format.

I have also improved Windows hardware detection by using a bit of WMI (Windows Management Instrumentation).

Best regards
Koldo


Best regards
Iñaki
Re: New functions to SysInfo [message #21816 is a reply to message #21602] Sat, 06 June 2009 15:36 Go to previous messageGo to previous message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello all

I have updated SysInfo documentation and added some functions for Posix and Windows:

- TrashBin handling

--FileToTrashBin: Deletes file by sending it to the Trash Bin.
--TrashBinGetCount: Returns the number of items (files and directories) located in the Trash Bin.
--TrashBinClear: Removes all the items (files and directories) located in the Trash Bin.


- Desktop Wall paper

--SetDesktopWallPaper
Sets desktop wallpaper. Supports Gnome, Kde v3 and Windows desktops.

---In Gnome, file has to be .png
---In Kde, file has to be .png, .gif or .jpg
---In Windows, file has to be .bmp

If path is empty, the desktop wallpaper is removed.

Best regards
Koldo


Best regards
Iñaki
Previous Topic: How to get/set keyboard layout in u++
Next Topic: TabBar translation file
Goto Forum:
  


Current Time: Fri Mar 29 11:22:35 CET 2024

Total time taken to generate the page: 0.01944 seconds