Link to home
Start Free TrialLog in
Avatar of EasyToHelp
EasyToHelpFlag for South Africa

asked on

How to have the ctrl button pressed on page load

Hi

I am currently using a Jquery selectable to allow users to select block.
It allows them to drag and select but i would also like to allow users to select individual blocks and this is achievable by having the ctrl key pressed when the page loads.
Avatar of Hans Langer
Hans Langer

You can detect they key pressed on almost any mouse event:

List of Mouse Event in JQuery

Every listener function will receive an "eventObject" where you can identify if control is pressed or not,
example:
$('#elementId').mouseup(function(eventObject){
    var isCtrlPressed = eventObject.ctrlKey;
    alert(isCtrlPressed )   // true or false whether ctrl is pressed or not 
  });

Open in new window

Avatar of Mrunal
hi,
have you done everything same as:
https://jqueryui.com/selectable/#display-grid

can you share your code?
Avatar of EasyToHelp

ASKER

Hi Mrunal

Yes that is what i had used,
Now if you press the control key the user is able to select  items 1 and 12.

I am using this on a mobile device so the user does not have a ctrl key that they can press,  how would it be possible for me to achieve this on a mobile device,is it possible to get the keypressed event to occur when the page is loaded.

Regards
ASKER CERTIFIED SOLUTION
Avatar of Mrunal
Mrunal
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial