Pages

Sunday, 30 October 2011

MOUSE GESTURES IMPLEMENTATION USING MESSAGE LOOPS

About Mouse gestures
        In recent times the use of mouse gestures to control the application is becoming increasingly common. For example, in smart phone, the user is asked to do some predefined finger movement to unlock the phone or to open an application. And similarly there are couple of computer applications which make use of mouse gestures.
        "Gestures" is a wide topic, some of which uses neural network as well. But please note that this blog talks only about mouse gestures and a sample code which implements that.
        As said earlier, an application can take inputs through either Mouse or Keyboard or through gestures. But when an application demands the input through mouse gestures, how exactly to provide that? Its very simple, click and hold the mouse (either left button or the right button depending on the application demand) and draw a predefined picture that the application recognizes and release the mouse click. This movement is interpreted as a "gesture". Simple isn't it? With that said, obviously it is possible to have unlimited number of gestures of varying complexity. However it is the application which defines the gestures to which user has to adhere. Following are some of the gestures that user find easy to use and aren't really difficult to recognize for an application.
   -> , <-, ^, | and etc. And some of the applications accept english alphabets as gesture.
               |  v

 
How to implement in .NET platform?
        There are multiple ways to implement mouse gestures. Basically, the mouse movements need to be captured when the gesture is made. And as you can expect, it can be done in multiple ways. But here I am going to discuss about Windows message loops for achieving the same (Read more about message loops here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644927(v=vs.85).aspx.
Fundamentally, Windows-based applications are event driven, they wait for system to send input to them. The system provides the input to the applications in the form of a message. System generates a message for every input event such as mouse clicks, mouse movement, key press and others. And therefore message loop become very handy for us to implement mouse gestures. With this infomation, let us dig and see how can message loops be used in .NET platform.

 
Working with Message Loops
        The .NET platform provides an inteface called "IMessageFilter" which allows an application to capture the message from the system. This interface provides a method called "PreFilterMessage" which helps in filtering out a message before it is dispatched. In other words, this method gives you the last message received in the message loop. Return value of this method is a boolean. Return true to filter the message and stop it being dispatched to the form or false to allow the message to flow to the form.

Usual procedure followed by the for developing an application that supports mouse gestures:
  1. Identify the gestures that you want to support.
  2. Create a message filter that looks for mouse click event (either left or right click depending on the requirement).
  3. Track for the mouse movements till the mouse click is released.
  4. Analyse the tracked mouse movement to identify the gesture and take the appropriate action.

Following is a sample application written C#.net which uses message loops to identify the mouse gestures.
This application is configured to identify four basic gestures.....
The application assumes mouse movements between left click of the mouse and release as the gesture.

//Code starts here...
namespace Sample
{
    //This application tries to identify following gestures.
    public enum gestureType : int
    {
        up = 0,
        down = 1,
        left = 2,
        right = 3,
        unidentified = 4
    }
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //Add the message filter here
            MyFilter filt = new MyFilter();
            Application.AddMessageFilter(filt);
        }
    }
    public class MyFilter : IMessageFilter
    {
        //Some of the constants are defined.
        //All these values can be seen in: http://www.autohotkey.com/docs/misc/SendMessageList.htm
        private const int WM_MOUSEMOVE = 0x0200;
        private const int WM_LBUTTONDOWN = 0x0201;
        private const int WM_LBUTTONUP = 0x0202;
       
        //Have an arraylist for storing the mouse movements.
        private ArrayList mouseMoves = new ArrayList();
        Boolean bCaptureMouseMove = false;
        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
        public bool PreFilterMessage(ref Message m)
        {
            if (bCaptureMouseMove == true)
            {
                if (m.Msg == WM_MOUSEMOVE)
                {
                    //add the mouse position into the arraylist
                    mouseMoves.Add(Cursor.Position);
                    return true;
                }
            }
            if (m.Msg == WM_LBUTTONDOWN)
            {
                //start capturing mouse moves.
                bCaptureMouseMove = true;
                mouseMoves.Add(Cursor.Position);
            }
            if (m.Msg == WM_LBUTTONUP)
            {
                //stop capturing mouse moves.
                bCaptureMouseMove = false;
                mouseMoves.Add(Cursor.Position);
                //Try to identify the gesture.
                identifyGesture();
            }
            return false;
        }

        private void identifyGesture()
        {
            gestureType direction = gestureType.unidentified;
            Point clickPos = (Point)mouseMoves[0];
            Point clickReleasePos = (Point)mouseMoves[mouseMoves.Count - 1];
            Point difference = new Point();
            difference.X = clickPos.X - clickReleasePos.X;
            difference.Y = clickPos.Y - clickReleasePos.Y;
            if (Math.Abs(difference.X) > Math.Abs(difference.Y))
            {
                if (difference.X > 0)
                {
                    direction = gestureType.left;
                    MessageBox.Show("Left");
                }
                else
                {
                    direction = gestureType.right;
                    MessageBox.Show("Right");
                }
            }
            else if (Math.Abs(difference.Y) > Math.Abs(difference.X))
            {
                if (difference.Y > 0)
                {
                    direction = gestureType.up;
                    MessageBox.Show("Up");
                }
                else
                {
                    direction = gestureType.down;
                    MessageBox.Show("Down");
                }
            }
            else
            {
                direction = gestureType.unidentified;
                MessageBox.Show("Not identified");
            }
        }
    }
}

Wednesday, 6 July 2011

INDIA AGAINST CORRUPTION and POSSIBLE REFORMS


K
Overview:
    Over last few months, we all have witnessed a huge support from Indians against corruption and on the inclusion of a strong Lokpal Bill. However it may not be complete solution to abolish the current issue of "corruption". This article makes an attempt to support not only the inclusion of Lokpal-Bill, but also on possible reforms needed to completely abolish it (both from Government and General Public).
    While going through the below article, request is not to get biased on any of the contents, rather provide your sincere comments on "corruption in India and possible reforms". The intent of this article is to share the views and get into a solid solution towards fighting against corruption, bringing reforms and building a stronger India which is now facing many such prominent issues.
    This article focuses only on the reforms expected from Government side. Expectations from General public will be posted in the next version of this article.

Motivation: 
    There are thousands of discussions happening over the CORRUPTION issue. Most prominent one is to support Anna Hazare for his cause. This is completely agreed with this and am part of this fight. But there were some points (critics) which grabbed my attention and this is an attempt to rationalize such critics.

Contents:
  1. What is inferred from the "movement of Anna Hazare and team (Jan-Lokpal Bill)".
  2. Response of political parties (Congress in particular) over the Lokpal Bill.
  3. Irrelevant critics on proposed Jan-Lokpal Bill.
  4. Possible reforms needed in addition to Jan-Lokpal Bill. (new ideas/modifications/suggestions from readers are always welcome)
  5. Last byte..
Explanation:

1. What is inferred from the "movement of Anna Hazare and team (Jan-Lokpal Bill)":
    India is tired of corruption. In other words it has become helpless on this issue. Jan-Lokpal bill is an attempt to form a strong law to fight against. It has to be noted that this bill is not drafted by Anna Hazare. It is a collaborative effort of several masterminds (which include retired judges, social activists, people suggestions etc..).
    Point of inference here is: This is a people movement. The support Anna received shows that people of India are desperate to see a better India.

2. Response of political parties (Congress in particular) over the Lokpal Bill:

    Though a political leader is a representative of people, however, political parties (especially Congress) don't seem to understand this basic meaning of democracy. Their act seems to be such that "they are trying to save democracy by cornering out the social activists who are now the actual voice of people "!!. Strange! but true.

3. Irrelevant critics on proposed Jan-Lokpal Bill:

     It is also witnessed that there are several statements by government chair persons to systematically bring down the movement against corruption. Below is list of few such things and my views on them:
  • PM and chief justice inclusion under Lokpal:
         This issue is being discussed over and over in all the news channels. But to be frank, this is not an issue to be hyped at all!!  Every citizen of India should be investigated "if" he is accused. (no matter if he is a PM, justice OR common man).
         This is just diverting the attention of public from the actual issue..
  • Destruction of democracy:
         Simple answer is, democracy is a system to represent people's view. Politicians should have done this, but now is being done by social activists.
  • Independent body running parallel to government and trying to threaten the whole system of democracy:
         It has been repeatedly confirmed by the social activists that, this committee is strictly restricted to "only look and prosecute the cases against corruption". Won't intervene in any other matters/decisions of government. Hence no question of a parallel body / threatening government of democracy.
  • etc..
4. Possible reforms needed in addition to Jan-Lokpal Bill:

    This is interesting and needs more attention. Jan-Lokpal Bill concentrates on formulating a "strong law" to prosecute and punish only the "accused person". At the present situation this law is a must. For the time being let us assume that government will pass the strong Lokpal bill. But does this solve the corruption issue which India is facing today? I have seen several people commenting on news channel forums saying : "Formulation of a law can't help in overcoming corruption". Practically this is true!! Just think of yourself going to a government office for a work getting done. You will always concentrate on completion of your work than going to file case on people who are asking bribe. Jan-Lokpal Bill won't help unless somebody is accused.
    This says we need something more to address corruption in addition to strong Lokpal Bill. Below discussion focuses on some of the probable solutions:
  1. Build a very strong software/database which will record all government activities (tenders,schemes etc..) and is accessible online. Except the defense secretes, which would harm National Integrity, everything else should be open to everyone.(RTI act has already given this right and this will allow everyone to use the facility without need of asking government for details).
            Ex: a road tender. All tender activities should be recorded and open to everybody. Whoever bids for it, should be available online instantly and when the last date is reached, whoever has submitted with the lowest bidding rate should be automatically allotted. This easily avoids the high level "influences". If I take the example of commonwealth games scam, it is now revealed that one of the tender was decided even before that company submitted it's bidding!
  2. As it is already started, every Indian citizen should be given with a "unique identity no." which should contain each and every details about him. The details should include, his address, his bank account no.s, his demat accounts, status of cylinders, driving license, PAN, passport details, family relations, thumb impression, retinal info etc... (everything which is needed for government while coming up with new schemes for people of India and can be openly published). The central database similar to mentioned above should store information of every citizen of India. Requirements for such a strong software should be:
    • Software should be so strong to detect any duplicate entries (this can easily be checked by cross verifying face detection, thumb impression and retinal info).
            - This easily avoids many people illegally having several ration cards in same name.
            - Misusing several government schemes.
    • Store all these information on a central database similar to mentioned in point 1.
    • The information stored in this database should be considered as golden from all government sectors, private sectors. Believe it or not, if we do this, many day today operations will become easy, transparent, speedy. (ex. applying a cylinder, taking loan, applying ration card, etc..).
    • This central database would greatly help in estimating how much will be the expense for any new scheme which government would be planning to bring. The software should also show who all (citizens) are the beneficiary of this scheme instantly.
            Now media people can handpick random no. of people in this list and ask them directly if they are beneficiaries or not. If any discrepancy, then the related government official can directly be sacked by the Strong Lokpal Bill and speedy court.
  3. The database/software should also store bank account no.s (if any) of each person against his name. "Any account which is not defined against any of the citizen, but exists in any Bank, should be declared as National Asset OR belongs to government". In addition to this, there should be a constant track foreign money exchange by any account.
    Direct advantages of such a system:
    • This would greatly reduce the "black money" issue!
    • This will also automatically bring all those businessmen and other people who are avoiding the tax by showing wrong no.s to come directly inside the tax liability.
    • It is very easy to estimate the tax of each person and I am sure, it would increase the revenue of tax dept.
    • Also if any new account is created in any of the BANK, it should be linked with one of the existing name in central data base. His signature, while creating the account should exactly match the one present in his details present in the central database. Now this would avoid creating accounts with "unanimous names, illegal addresses etc...".
  4. Every user should be given with a password (as given for any online Bank account). There should be a provision for submitting a request to any of the government dept. (ex: consider applying for a cylinder).
            This concept is exactly same as the complaint/request being received by any mobile operators for a service and completion of service within specified time.
  5. In case a user (common man) doesn't know about computer, then whenever he approaches a government office, his request should be entered against his database, assigned to corresponding officer and process status also should be updated regularly by an appointed government operator.
    • This is very equivalent to calling one customer care executive and he will take care of the rest.
    • Ideally to say, there should be a big screen in every government dept (taluk level) displaying all the requests made by people in that area and the processing status/probable date of completion of their request. (just projecting the results as is done in CET seat selection centers)
    • It is already known what all kind of work can be done by a office and how much time a task would take for an officer. Once the operator assigns the task to corresponding officers, software should be intelligent to decide the time required for completion of a work by looking at the category of work, workload on the corresponding officer, his leaves etc.. and automatically display in how many days the work should be completed.
    • If executed effectively, then officer sitting idle at remote office can also handle the request of another area. (boosts up the efficiency of government activities).
    • In case the work gets delayed by an officer, then the software should assign that officer's performance as degraded one and his % of completion of work should automatically get reflected in his salary.
      This would help in 3 ways:
             - deciding the performance of lazy government workers
             - avoid people running behind the offices/officers first to find out where their work can be done and then for getting their work done.
             - Avoid bribing the officers (because now it could be taken up by a remote officer also..)
5. Last byte..:

    The solutions provided above may seem hypothetical one. But just think for a while and observe that the solution offered above is not something which is not at all existing. It is already followed by several private sectors (like Banking, Mobile service etc..) for their effective, transparent and speedy execution. These sophisticated softwares and database are also already present and in use. Here the emphasis is just on bringing such services to the government sectors.These reforms in addition to the very strong "Lokpal Bill" and a speedy court will greatly help in avoiding several issues, not only corruption.
    To be very brief, all we need is a very sophisticated software, centralized storage system, syncing every sectors with this system, training for the government officials on this and an one time collection of details from every citizen.
    But following issues can effectively be addressed:
  • Corruption/bribing at different levels. (small or higher level)
  • Black money issue.
  • Reducing the effort of common man running behind officers/offices for getting even a small piece of info/work.
  • Avoiding high level influences/lobbies in getting contracts/tenders.
  • Proper tax estimation. (I am not aware where all it could help)
  • Avoid unanimous accounts in several Banks.
  • Effective execution of any government scheme. (Because in democracy, news channel have great deal of freedom and can access this database to see if the beneficiaries mentioned in these schemes are actually benefited OR simply no.s produced by government officials)
Expectations from General public will be posted in the next version of this article.... 
We request you to share your view on this topic... 

Wednesday, 15 June 2011

Lunar Eclipse

Here is a small article about Lunar Eclipse.
Lunar Eclipse means, Earth coming in between Sun and the Moon for a small duration of time and hence creating a shadow on Moon to make it hidden. At one moment of time, the Moon completely gets covered by the shadow of Earth which is the height of the event (Eclipse). During the process of Eclipse, the Moon may be completely covered or partially covered by the shadow of Earth. Based on the visibility of Moon, the Lunar Eclipse was differentiated as 2 types: Umbra and Penumbra.
Umbra:
It is the darkest part of Shadow during which the light source is completely blocked by occluding body (earth). This makes, the observer to experience a complete/dark eclipse.
Penumbra
"Penu" is a Latin word which means "Almost, nearly" and "umbra" means: shadow. As the name itself indicates, only a portion of the light source is obscured by the occluding body. Hence user experiences a partial eclipse.


References:
http://www.yreach.com/bengaluru/news/environment/space-news/lunar-eclipse-on-15-june-2011.html http://en.wikipedia.org/wiki/Umbra#Penumbra

Tuesday, 14 June 2011

ಚಂದ್ರ ಗ್ರಹಣ ಕಾಲದಲ್ಲಿ ಏನು ಮಾಡವು ???


ಎಲ್ಲರಿಗು ನನ್ನ ವಂದನೆಗಳು....


ಇವತ್ತು ಖಗ್ರಾಸ್ ಚಂದ್ರ ಗ್ರಹಣ ... ನಿಂಗೊಕೆಲ್ಲ ಗೊತ್ತಿದ್ದದ್ದೇ .... ಕೆಲವು ರಾಶಿಗಳಿಗೆ ಟೈಮ್ ಚೊಲೋ ಇಲ್ಲೇ ಹೇಳಿ ಓದಿದ್ದೆ ... ಅವುಹ್ ಎಂತ ಮಾಡವು ಹೇಳಿ ಇಲ್ಲಿ ಬರ್ದಿದ್ದೆ ... ನೋಡಿ...
ಇಲ್ಲಿ ಕೆಳಗಡೆ ಒಂದು ಮಂತ್ರ ಇದ್ದು.. ಅದನ್ನ ಗ್ರಹಣ ಕಾಲದಲ್ಲಿ ಪಠನ ಮಾಡವಡಾ .. ಎಲ್ಲ ಒಳ್ಳೇದ್ ಆಗ್ತಡಾ ...

ಯಾವ ಯಾವ ರಾಶಿಯವು ಈ ಮಂತ್ರ ಹೇಳವು ???
ವ್ರಶ್ಚಿಕ, ಸಿಂಹ, ಧನಸ್ಸು, ಮೇಷ ( ಅಶುಭ ಫಲ ಇರುವವರು )

-----------------------------------------------------------------------------------------------------

ಯೋಹ್ ಸೌ ವಜ್ರಧರೋ ದೇವಃ ಆದಿತ್ಯಾನಾಂ ಪ್ರಭುರ್ಮತಃ |
ಚಂದ್ರಗ್ರಹೋ ಪರಾಗೋತ್ಥ್ ಗ್ರಹಪೀಡಾಂ ವ್ಯಪೋಹತು ||೧||

ಯೋ ಸೌ ದಂಡಧರೋ ದೇವಃ ಯಮೋ ಮಹಿಷ ವಾಹನಃ |
ಚಂದ್ರಗ್ರಹೋ ಪರಾಗೋತ್ಥ್ ಗ್ರಹಪೀಡಾಂ ವ್ಯಪೋಹತು ||೨||

ಯೋ ಸೌ ಶೂಲಧರೋ ದೇವಃ ಪಿನಾಕೀ ವ್ರಶವಾಹನಃ |  
ಚಂದ್ರಗ್ರಹೋ ಪರಾಗೋತ್ಥ್ ಗ್ರಹಪೀಡಾಂ ವ್ಯಪೋಹತು ||೩||
------------------------------------------------------------------------------------------------------

ನಿಂಗೋಕೆ ಇಷ್ಟ ಆದ್ರೆ, ದಯಮಾಡಿ ಕೆಳಗೆ ಕಾಮೆಂಟ್ ಬರೇರಿ ಮತ್ತು ನಿಂಗೋಳ ಫ್ರೆಂಡ್ಸ್ ಗೂ ಹೇಳಿ ... 

See you soon with one another interesting blog... Keep watching our site: freekyfive.blogspot.com

Reference:
VijayaKarnataka News Paper (Dated on 15-06-2011)

Monday, 13 June 2011

Rajanikanth Jokes...... It's all about Rajanikanth........ Collection of Rajanikanth Jokes

Hi friends,
I have collected few Rajanikanth Jokes and sharing with you guys for fun... It's all for fun...



-- Fact is: The missing part of Apple in Apple's logo is eaten by Rajanikanth :-P ....
-- Rajanikanth once fought with Superman and the challenge was, the looser has to wear the underwear outside... 


-- If Rajnikant ever got caught for speeding, he’d let the cops off with a warning


-- Only Rajinikanth can kill the Dead Sea.


-- When Rajinikanth does push-ups, he isn't lifting himself up. He is pushing the earth down.


-- There is no such thing as evolution, it's just a list of creatures that Rajinikanth allowed to live.


-- .Rajnikanth can divide by zero.


-- Rajinikanth can drown a fish. 


-- Rajinikanth can delete the Recycle Bin. 


-- Rajinikanth once got into a fight with a VCR player. Now it plays DVDs. 


-- Rajinikanth once kicked a horse in the chin. Its descendants are today called giraffes. 


-- Rajinikanth once ordered a plate of idli in McDonald's, and got it.


-- Rajinikanth can build a snowman out of rain. 


-- Rajinikanth has counted to infinity, twice. 


-- Rajinikanth once got into a knife-fight. The knife lost. 


-- Rajinikanth can play the violin with a piano. 


-- The only man who ever outsmarted Rajinikanth was Stephen Hawking, and he got what he deserved.


-- Rajinikanth doesn't breathe. Air hides in his lungs for protection.


-- There are no weapons of mass destruction in Iraq. Rajinikanth lives in Chennai.


-- Rajinikanth has already been to Mars, that's why there are no signs of life there.


-- Rajinikanth doesn't move at the speed of light. Light moves at the speed of Rajinikanth.


-- Water boils faster when Rajinikanth stares at it.


-- Rajinikanth kills two stones with one bird.


-- Google won't find Rajinikanth because you don't find Rajinikanth; Rajinikanth finds you.


-- Rajinikanth leaves messages before the beep.


-- Rajinikanth once warned a young girl to be good "or else". The result? Mother Teresa.


-- Rajinikanth killed Spiderman using Baygon Anti Bug Spray. 


-- Rajinikanth goes to court and sentences the judge.


-- Rajinikanth can teach an old dog new tricks.


-- Rajinikanth once had a heart attack. His heart lost. 


-- Rajinikant is so fast, he can run around the world and punch himself in the back of the head.


-- Rajinikant doesn’t wear a watch. He decides what time it is.


-- When you say “no one is perfect”, Rajinikant takes this as a personal insult. 


-- In an average living room there are 1,242 objects Rajinikanth could use to kill you, including the room itself.


-- The statement "nobody can cheat death", is a personal insult to Rajnikanth. Rajni cheats and fools death everyday.


-- When Rajnikanth is asked to kill some one he doesn't know, he shoots the bullet and directs it the day he finds out.


-- Rajinikanth knows what women really want.


-- Rajinikanth can answer a missed call.


-- Rajinikanth doesn't need a visa to travel abroad, he just jumps from the tallest building in Chennai and holds himself in the air while the earth rotates.


-- Where there is a will, there is a way. Where there is Rajinikanth, there is no other way. 


-- Rajinikanth's every step creates a mini whirlwind. Hurricane Katrina was the result of a morning jog. 


-- Rajinikant doesn’t bowl strikes, he just knocks down one pin and the other nine faint out of fear. 


-- There is no such thing as global warming. Rajinikanth was feeling cold, so brought the sun closer to heat the earth up.


-- We live in an expanding universe. All of it is trying to get away from Rajinikanth.


-- If at first you don't succeed, you're not Rajinikanth.


-- Rajinikanth does not style his hair. It lays perfectly in place out of sheer terror.


-- When Rajinikanth plays Monopoly, it affects the actual world economy.


Most funniest joke of Rajanikanth :
You know why you people see "Web page cannot found or HTTP error ..." kind of errors when you try to access any webpage? It's because, Rajanikanth is trying to access it and hence the webserver gone down due to feat... 


If you have any jokes to share, please add the same using "comments" option below this post.



Files transfer between Linux and Windows

Dear All,
Wondering "How to transfer files between Windows and Linux systems"??? Here you go with the steps....
There are multiple ways to share/transfer the files between Linux and Windows. Here I will talk 2 ways to achieve the same.
One way:

  1. Share a folder in your Windows machine with a specific user name and credentials (ex: share folder is: Share and Username: temp and password: temp)
  2. Log in to your Linux box/VM/machine using root.
  3. Create a directory in /mnt (where the Windows share will be mounted. ex:mount_windows_share)
  4. Type the following command to have windows share mounted:                                                                 # mount -t smbfs -o username=temp Windows_Share_Location /mnt/mount_windows_share
  5. You will be prompted to enter the password. Enter "temp" as the passowrd (see the step 2).
The above mentioned steps will mount the windows share on to the /mnt/mount_windows_share directory. Now you will see the contents of windows (share) directory in /mnt/mount_windows_share. If you want to transfer any files from Linux to Windows, then copy the file from Linux machine to /mnt/mount_windows_share directory (which will automatically get copied to windows share folder).

2nd way is:
  1. Install an application called "WinSCP" in your Windows environment.  
  2. Make sure you have Enabled SSH on your Linux system.
  3. Launch WinSCP.
  4. Enter the IP address, user name and credentials in the WinSCP (of Linux System to which you want to connect to ).
  5. You will see a windows explorer listing all the files available in the Linux machine.
Now, you can copy and paste files as iff like a windows environment. ...

Please leave your comment once you read it using the "comment" option provided below. Thanks for your cooperation.