JavaScript - Sending Keystrokes
Hi can someone modify this script so the key '1' will send the ENTER command.
It's a script for an app to control my computer from my phone. So far the middle button and the number 5 send left click. 0 sends the right click. When you press the left soft key it opens the text input to send to the computer. but as it stands there is no way to then press enter. If someone could do that for me that would be great. Or at least show me how.. thanks var leftDown = false; var rightDown = false; var leftLocked = false; var rightLocked = false; var acceleration_factor = 1; var widget = CreateKeypadScreen( "myKeypad_" ); widget.title = "Mouse Pointing"; if( theTerminal.supportsPen ) { widget.CreateRow("Use the blank area like you'd use a trackpad; use up/down to scroll.", scCenter, scWrap, scSmall); } else { widget.CreateRow("Use the directional controls.", scCenter, scWrap, scSmall); } widget.sendsPenEvents = true; widget.keyRepeatInterval = 0.001; widget.keyRepeatDelay = 0.2; theTerminal.Push(widget); function myKeypad_Exit(theScreen) { if( leftDown ) { leftDown = false; SendMouseEvent(0, 0, 0, 1, 0); } if( rightDown ) { rightDown = false; SendMouseEvent(0, 0, 0, 0, 1); } } function showSearchable() { var textField = CreateTextFieldDialog( "textToPrintOnComputer_"); textField.name = "Text to show on computer"; textField.title = "Text to show on computer"; textField.prompt = "Write text to show on computer:"; textField.value = ""; textField.maxLength = 0; theTerminal.Push(textField); theTerminal.Push(textField) } function textToPrintOnComputer_OK(textField) { convertToUnicodeAndSend(textField.value); } function convertToUnicodeAndSend(incomingText) { var theText = incomingText; var toUnicode = ""; for(var i=0;i<theText.length;i++) { toUnicode = theText.charCodeAt(i); SendUnicodeKeystroke(toUnicode); } } function myKeypad_KeyDown(theScreen, theKey) { if(theKey == "f") { showSearchable(); } else if( theKey == "<") { SendVirtualKeystroke( 0x08, true, false, false, false ) ; } //what does this line actually do? //if( handleKeyMove( theKey ) ) return; else if( theKey == "s" || theKey == "5" ) { if( ! leftDown ) { leftDown = true; SendMouseEvent(0, 0, 0, -1, 0); } if( leftLocked ) { SendMouseEvent(0, 0, 0, 1, 0); leftLocked = false; leftDown = false; ShowMessage("Left button unlocked"); } if( rightLocked ) { SendMouseEvent(0, 0, 0, 1, 0); rightLocked = false; rightDown = false; ShowMessage("Right button unlocked"); } } else if( theKey == ">" || theKey == "0" ) { if( ! rightDown ) { rightDown = true; SendMouseEvent(0, 0, 0, 0, -1); } if( rightLocked ) { SendMouseEvent(0, 0, 0, 1, 0); rightLocked = false; rightDown = false; ShowMessage("Right button unlocked"); } if( leftLocked ) { SendMouseEvent(0, 0, 0, 1, 0); leftLocked = false; leftDown = false; ShowMessage("Left button unlocked"); } } } function myKeypad_KeyRepeat(theScreen, theKey) { if( handleKeyMove( theKey ) ) { acceleration_factor += 0.05; return; } if( theKey == "s" || theKey == "5" ) { if( leftDown && ! leftLocked ) { leftLocked = true; ShowMessage("Left button locked"); } } else if( theKey == ">" || theKey == "0" ) { if( rightDown && ! rightLocked ) { rightLocked = true; ShowMessage("Right button locked"); } } } function myKeypad_KeyUp(theScreen, theKey) { acceleration_factor = 1; if( theKey == "s" || theKey == "5" ) { if( leftDown && ! leftLocked ) { leftDown = false; SendMouseEvent(0, 0, 0, 1, 0); } } else if( theKey == ">" || theKey == "0" ) { if( rightDown && ! rightLocked ) { rightDown = false; SendMouseEvent(0, 0, 0, 0, 1); } } } function myKeypad_PenTap(theScreen) { if( leftLocked ) { SendMouseEvent(0, 0, 0, 1, 0); leftLocked = false; leftDown = false; ShowMessage("Left button unlocked"); } else { if( ! leftDown ) { SendMouseEvent(0, 0, 0, -1, 0); } SendMouseEvent(0, 0, 0, 1, 0); leftDown = false; } } function myKeypad_PenLock(theScreen) { if( ! leftDown && ! leftLocked ) { SendMouseEvent(0, 0, 0, -1, 0); leftDown = true; leftLocked = true; ShowMessage("Left button locked"); } } function accelerate(v) { if( v > 8 || v < -8 ) { return v*4 } else if( v > 4 || v < -4 ) { return v*2 } return v; } function myKeypad_PenMove(theScreen, dx, dy) { dx = accelerate(dx); dy = accelerate(dy); SendMouseEvent(dx, dy, 0, 0, 0); } function handleKeyMove( theKey ) { var dx = 0; var dy = 0; var scroll = 0; if( theTerminal.supportsPen ) { if( theKey == ">" || theKey == "6" ) { dx = 1; } else if( theKey == "<" || theKey == "4" ) { dx = -1; } else if( theKey == "v" || theKey == "d" || theKey == "8" ) { scroll = -1; } else if( theKey == "^" || theKey == "u" || theKey == "2" ) { scroll = 1; } else if( theKey == "1" ) { dx = -1; dy = -1; } else if( theKey == "3" ) { dx = 1; dy = -1; } else if( theKey == "7" ) { dx = -1; dy = 1; } else if( theKey == "9" ) { dx = 1; dy = 1; } else { return false; } } else { if( theKey == ">" || theKey == "6" ) { dx = 1; } else if( theKey == "<" || theKey == "4" ) { dx = -1; } else if( theKey == "v" || theKey == "d" || theKey == "8" ) { dy = 1; } else if( theKey == "^" || theKey == "u" || theKey == "2" ) { dy = -1; } else if( theKey == "1" ) { dx = -1; dy = -1; } else if( theKey == "3" ) { dx = 1; dy = -1; } else if( theKey == "7" ) { dx = -1; dy = 1; } else if( theKey == "9" ) { dx = 1; dy = 1; } else { return false; } } if( dx != 0 || dy != 0 ) { SendMouseEvent(dx*acceleration_factor, dy*acceleration_factor, 0, 0, 0); } if( scroll != 0 ) { SendMouseEvent(0, 0, scroll, 0, 0); } return true; } Similar TutorialsIs it possible to detect keystrokes on the keyboard? I want to detect the arrow keys in particular. I'm going through the online reference links in the sticky now, great resource! HI All, I am using triple ajax dropdwon in my php file.In my form i have species_scientifc_name & on select I am sending its id to a php file for retriving data for second dependent dropdown box, Here I need to get this id in form action file. How to get this value, Any idea? Thnaks in Advance!! seems easy yet frustrating trying to learn how. i set up a column in the MySql database that holds an integer, lets call it IMG_INDEX; easy enough. in my prgm.php, i need to use the values stored in IMG_INDEX (in the database) to contol which image is currently displayed in the browser. i need to be able to update to value of IMG_INDEX in the database from the code. i need to be able to retrieve the value of IMG_INDEX from the database with the code. note: this is NOT a user input thing, or a display of database info thing. i'm using IMG_INDEX as a switch to control which image is displayed at different times during a web browing session. ?? so here is the question ?? how do i send a new integer (like 2) to the database and store it in IMG_INDEX ? how do i retrieve the value of IMG_INDEX from the database ? i need to do this all from the javascript area in the head of the php code, and occasionally from the body area of the php code. if you have a tip, i'd really appreciate your help. thank you, Paul Williams todays weather in Kalispell, MT COLD i say again COLD, COLD, COLD. brrrrrrrrrrrr hello, can someone please show me why only one of the following functions work. I have one form with 2 different inputs where the text should at the same time as typing, be automatically be entered into two other divs thx Code: function redundantTextInstall(input,idArr) { var i = 0, val = input.value; while (idArr[i]) { document.getElementById(idArr[i]).innerHTML = val; i++; } } function installtext(input,idArr) { var o = 0, val = input.value; while (idArr[o]) { document.getElementById(idArr[o]).innerHTML = val; o++; } } window.onload = function () { document.someForm.os2.onkeyup = function () { var ids = ['addsx1', 'addsx2', 'addsx3', 'addsx4', 'addsx5', 'addsx6', 'addsx7', 'addsx8', 'addsx9', 'addsx10']; redundantTextInstall(this,ids); }; }; window.onload = function () { document.someForm.os3.onkeyup = function () { var abs = ['addsA', 'addsB', 'addsC', 'addsD', 'addsE', 'addsF', 'addsG', 'addsH', 'addsI', 'addsJ']; installtext(this,abs); }; }; Hello to all! Can I have 2 variables upon one select? The code below is created dinamicly with php from a database, and displays a dropdown select box, the only thing is that the values: Oliver Franchis, Pedro pastor, Maria China... have unique ID's and when the name is selected I would like the ID allso to be. Code: <!-- Populate list with friends START--> var newTextbox = document.createElement('select'); newTextbox.className = 'fn-select'; newTextbox.name = "opcion"; //First user in the populated select menu is the person Loged in var op1 = new Option("", "Oliver Franchis"); newTextbox.appendChild(op1); var txt1 = document.createTextNode('Me | Oliver Franchis'); op1.appendChild(txt1); //Next users are my friends in the database var op1 = new Option("", "Pedro pastor"); newTextbox.appendChild(op1); var txt1 = document.createTextNode('Pedro pastor'); op1.appendChild(txt1); var op1 = new Option("", "Maria China"); newTextbox.appendChild(op1); var txt1 = document.createTextNode('Maria China'); op1.appendChild(txt1); var op1 = new Option("", "Juan Testing"); newTextbox.appendChild(op1); var txt1 = document.createTextNode('Juan Testing'); op1.appendChild(txt1); var op1 = new Option("", "Carmen Hernandez"); newTextbox.appendChild(op1); var txt1 = document.createTextNode('Carmen Hernandez'); op1.appendChild(txt1); var op1 = new Option("", "Eduardo Palote"); newTextbox.appendChild(op1); var txt1 = document.createTextNode('Eduardo Pajote'); op1.appendChild(txt1); editAreaText.appendChild(newTextbox); editArea.appendChild(editAreaText); <!-- Populate list with friends END--> This is the function on the index.php page: Code: function saveNote (note) { resetAjax(); var photoId = note.container.element.id; ajax.setVar('action', 'save'); ajax.setVar('photo_id', photoId); ajax.setVar('note_id', note.id); ajax.setVar('left', note.rect.left); ajax.setVar('top', note.rect.top); ajax.setVar('width', note.rect.width); ajax.setVar('height', note.rect.height); ajax.encVar('text', note.gui.TextBox.value); ajax.runAJAX(); var statusDiv = document.getElementById('PhotoNoteStatus'); ajax.onCompletion = function () {statusDiv.innerHTML = "<p>Note saved.</p>"; } return 1; } Hi, I have a script that has a form and i need it to send to an email address. The send button has an onclick with send() as its action, the js file has a send function but no way of inputting an email address, I though of adding .submit() or .post() jquery items but I am having trouble. Basically the script was given to me as is because there was no need for it and i wanted to get it to work. an suggestions or ideas? regards! I cannot figure out how to return the array back to the main method! what am I doing wrong?? import java.util.*; //lab 3 public class Prices { public static void main(String[] args) { double []array; array = new double[10]; double fullPrice; fullPrice = fillPrices(array); System.out.println("testing"); } public static double fillPrices(double []tenValues) { Scanner input = new Scanner(System.in); double prices; System.out.println("Please enter 10 prices: "); for (int i = 0; i < 10; i++) tenValues[i] = input.nextDouble(); return tenValues; } } I thought you return an array by simply return (array name); Am i missing something? Thanks a bunch for whoever takes the time to help me! Hello, I need to solve the following task on my website: I have products with add to cart button, like this: Code: <form action="cart.php" method="post" id="_cart" name="_cart"> <input type="hidden" name="prodid" value="Product1" /> <a href="javascript: AddToCart()"> <img src="/images/design/buynow.gif" /> </a> </form> However, it doesn't work, since i have the same value under the name of each form: "_cart". Is there any way i still can send a form regardless the name of the form? I tried to use "onclick", like this: Code: <a href="javascript: void(0);" onclick="document._cart[0].submit();return false;"> However, i still have to change the value under the _cart element from 0 to the number of my forms. I need just submit a form itself, with the same form names. For some reason i cannt use the html submit button. Everything should be done with JavaScript. I beleive this text is not hard for understanding ) Look forward to your help Guys. When I send via GET using XMLHttpRequest to a PHP script then the data is received, but if I do the same with POST then nothing makes it through. Here's my simple JavaScript function (tested in Firefox only) which works with GET but apparently won't send POST data: Code: function requestXML(url, post) { xml_request = false; if (window.XMLHttpRequest) { try { xml_request = new XMLHttpRequest(); } catch(e) { xml_request = false; } } if (xml_request) { xml_request.onreadystatechange = processChange; // Check for POST values. if (post) { xml_request.open("POST", url, true); xml_request.send(post); } else { xml_request.open("GET", url, true); xml_request.send(""); } } } It is called like-so with POST: Code: onClick="requestXML('http://localhost/update.php', this.name + '=' + this.value)" It is called like-so with GET: Code: onClick="requestXML('http://localhost/update.php?' + this.name + '=' + this.value)" The PHP script that responds simply executes print_r($_REQUEST); and the JavaScript function processChange simply displays the output (or an error) in an alert box. If I send via GET, then the alert box displays the values sent. With POST, the alert box is empty. Any ideas what might be gumming up the works? anyone know a script or way to change images based on radio button on another page or way to send value or src of an image to another page and way to have it show up.
hi, My server has an xml configuration file which I want to receive to my browser. I can do HTTPrequset directly to the file config.xml and get it in the responseXML, but I want to do it im more secure way, so the post request will be to some script ("python" in my case), which will open and read the file. if my xml file looks like this: <test>some_data</test> what shoud be the content of the response? I m trying to send data to my database (Mysql). When I enter things in the prompt box it doesn t go to my database. Can someone tell me why, please? Here is my code: <script type="text/javascript"> function show_prompt() { var name=prompt("question"); if (name!=null && name!="") { //set the hidden input value to the value entered in the prompt document.input.purpose.value = name; //document.input referring to the form named 'input' document.input.submit(); //submit the form } } </script> <form id="propose" name="input" action="insertpropose.php" method="post"><br/> <input type="submit" onclick="show_prompt()" value="propose" /> <input type="hidden" name="propose" value=""> </form> and the insertpropose.php form is: $propose=$_POST['propose']; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO propose VALUES ('','$propose')"; mysql_query($query); mysql_close(); Hi there How to send data from a text feild in GET method using an AJAX call... I already have codes working Code: to = "interfaces/add_department.jsp"; parm = "name="+name.value+ "&name2="+name2.value; alert(parm) post(to,parm,callBackFunctionForAddDepartment); Here the variable name may have "me&you" or "me you" like that.... so how do i encode it so that it reaches properly? Bare with me while I try and explain what I am trying to do. I have two servers with two websites. I want to use javascript to open up an url on another server with two paramaters. one will always be the same: allow=yes the other will change, it will take the current time and put it in the url paramater: hour=5minutes=30 I then want to encrypt this url paramater so that the user cannot intuitively edit it. I then want to on my other site decrypt the url paramater and if allow=yes hour=(the same value as current time) minute= (within 15 minutes of current time) then do one thing... if any of those values is false do another. Hey All, I've been fighting this one for a few months now, and it is causing me to have to create multiple functions that basically do the same thing. I am using the three functions below to replace text between two div tags on a page, based on a link that is clicked: Code: <td><a href=\"javascript:void(0)\" onclick=\"htmlData('ajax/loginContent.php', 'view=1','data=2','displayField=txtResult')\">Active Jobs</a></td>\n"; Then further down the page: Code: <div id="txtResult">replace this content</div> For some reason, I CANNOT send the div id name as a js variable. When I do it errors out. BUT if I replace displayField in the js functions below with "txtResult" it works fine. I am fairly new to js, so it is definitely possible that I am doing something incorrectly. Anyone have any ideas for me? Code: function GetXmlHttpObject(handler) { var objXMLHttp=null if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest() } else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") } return objXMLHttp } function stateChanged(displayField){ if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById(displayField).innerHTML= xmlHttp.responseText; } else { //alert(xmlHttp.status); } } // Will populate data based on input function htmlData(url, qStr, qStr2,displayField){ if (url.length==0) { document.getElementById(displayField).innerHTML=""; return; } xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } url=url+"?"+qStr; if(qStr2) url=url+"&"+qStr2; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=stateChanged(displayField); xmlHttp.open("GET",url,true) ; xmlHttp.send(null); } Hello, I am having a bit of a problem sending rich html emails. I just installed CK Editor on my hosting account and it appears to be working fine. But instead large colored fonts, I'm getting html tags only in my email. Links and emails appear to be working fine, though... So instead looking like this: Big Bold Blue. It looks like this: <p><span style='color: rgb(0, 0, 255);'><strong>Big Bold Blue.</strong></span></p> I also tried using mail() function in php, on its own, but that didn't work either. Can anyone help me out with this? I'm not very familiar with JavaScript... Thanks in advance! All, Trying to append data from an API to the frame source; not loading. master page: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript" language="javascript" name="mm_scormRTI" > <!-- Inserted by: // SCORM Runtime Wrapper // version 1.2.6 09/09/02 // Copyright 2000, 2001, 2002 Macromedia, Inc. All rights reserved. // ---------------------------------------------------- // define global var as handle to API object var mm_adl_API = null; // mm_getAPI, which calls findAPI as needed function mm_getAPI() {blah} // returns LMS API object (or null if not found) function findAPI(win) {bleh } // call LMSInitialize() function mm_adlOnload() {do api stuff- this is where i get ny value } // get the API, launch it mm_getAPI(); // --> </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DCB Document</title> </head> <body onLoad="mm_adlOnload()">this is a test;</p></p></p> <iframe src="blank.htm" width="100%" height="800" id="qualtrics" name="qualtrics"> <p>Your browser does not support iframes.</p> </iframe> </p></p> <input type="button" name="mm_finishBtn" value="Finish Lesson" onClick="mm_adlOnunload()" /> </body> </html> blank.htm: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript" language="javascript"> //test function loadit(){ var stud = window.opener.mm_adl_API.LMSGetValue("cmi.core.student_id"); var newlink = "https://mylink.com/stud_id=" + stud; parent.document.getElementById("qualtrics").src=newlink; } // --> </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DCB meta Document</title> </head> <body onLoad="loadit()">this is a test iframe</p></p></p> </body> </html> help? i'm kind of dizzy right now since i've tried X different versions...still working on it. the new URL doesnt load i want to get the stud_id from the API and append it to the url that i launch in the iframe I have a form with results and ID's for each field, I can get an alert to popup with the results, is there anyway to display this on the webpage? This is what I have so far: Code: document.getElementById('result').write(account.value +" "+ rep.value +" "+ error1.value +" "+ fix.value); along with this in the HTML: Code: <p id='result'></p> I have three radio button groups with different values. My script only works for one group. Please help! <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script> function emailTo(){ var emails = document.getElementsByName("email1"); var emailAdress = null; for(var i = 0; i < emails.length; i++){ if(emails[i].checked){ emailAdress = emails[i].value; } } if(emailAdress == null){ alert("select the email address"); return; } var mailto_link = 'mailto:'+emailAdress; var win = window.open(mailto_link,'emailWindow'); if (win && win.open &&!win.closed) win.close(); } </script> </head> <body> <p> <input type = "radio" name = "email1" value = "email1.com"/> recipient 1a <input type = "radio" name = "email1" value = "email1.com"> recipient 1b </p> <p> <input type = "radio" name = "email2" value = "email2.com"/> recipient 2a <input type = "radio" name = "email2" value = "email2.com"> recipient 2b</p> <p> <input type = "radio" name = "email3" value = "email3.com"/> recipient 3a <input type = "radio" name = "email3" value = "email3.com"> recipient 3b</p> <p> </p> <p> <input type = "button" onClick = "emailTo()" value = "Email"/> </p> </body> </html> How can I go about making it so JavaScript will not let a form submit unless a number entered into a field matches a pre-specified number? A guess.. Code: function validateForm() { if (document.forms["form"]["number"].value=="123") { submit} else {alert ("Cant submit because the number doesn't match."); return false; } } |