CGEventCreateMouseEvent Complie Error in Xcode 7 - ios

Even though CGEventCreateMouseEvent is not deprecated in Xcode 7, I am getting error
No matching function for call to 'CGEventCreateMouseEvent'
Please find the code that worked in Xcode 6 (SDK OSX 10.10)
-(void)sendMouseClick:(CGMouseButton)mouseBtn value:(uint32_t)value
{
int mouseEvent = 0;
if(mouseBtn == kCGMouseButtonLeft && value == 1) //left btn down
{
mouseEvent = kCGEventLeftMouseDown;
}
else if (mouseBtn == kCGMouseButtonLeft && value == 0) //left btn up
{
mouseEvent = kCGEventLeftMouseUp;
}
else if (mouseBtn == kCGMouseButtonRight && value == 1) //Right btn down
{
mouseEvent = kCGEventRightMouseDown;
}
else if (mouseBtn == kCGMouseButtonRight && value == 0) //Right btn up
{
mouseEvent = kCGEventRightMouseUp;
}
if(mouseEvent != 0) // a valid mouse event
{
CGEventRef ourEvent = CGEventCreate(NULL);
NSPoint mouseLoc = CGEventGetLocation(ourEvent); //get current mouse position
CGEventRef mouseClick = CGEventCreateMouseEvent(
NULL,
mouseEvent,
mouseLoc,
mouseBtn
);
CGEventPost(kCGHIDEventTap, mouseClick);
}
}
I have tried importing <CoreGraphics/CGEvent.h> but it made no difference. Any idea what is happening?

I found out that there was a type mismatch after SDK 10.11.
Changing,
int mouseEvent = 0
to
CGEventType mouseEvent = kCGEventNull;
Fixes the issue.

Related

How to fix " Property 'wheelDelta' does not exist on type 'WheelEvent' " while upgrading to angular 7,rxjs6?

I'm upgrading to angular7 with rxjs6: in mouseWheelEvent type I am getting "Property 'wheelDelta' does not exist on type 'WheelEvent'".
Do we have any alternative for wheelDelta?
mouseWheelFunc(event: MouseWheelEvent): void {
// var event = window.event || event; // old IE support
let delta = Math.max(-1, Math.min(1, (event.wheelDelta || -event.detail)));
if ( delta > 0) {
this.mouseWheelUp.emit(event);
} else if ( delta < 0) {
this.mouseWheelDown.emit(event);
}
// for IE
event.returnValue = false;
// for Chrome and Firefox
if ( event.preventDefault) {
event.preventDefault();
}
}
ERROR in
src/modules/components/numeric-stepper/mousewheel.directive.ts(23,49):
error TS2339: Property 'wheelDelta' does not exist on type
'WheelEvent'.
It seems like WheelEvent doesn't have this property anymore as it says. Now they added deltaY and deltaX.
Now you have to access event.deltaY instead of event.wheelData.
But deltaY has the opposite value of wheelData. That means when wheelData on the event was positive (scroll up) deltaY will be a negative number, and vice versa.
Example:
Change this:
zoomScroll(event: WheelEvent) {
if (event.wheelDelta > 0) {
this.zoomIn();
} else if (event.wheelDelta < 0) {
this.zoomOut();
}
}
For this:
zoomScroll(event: WheelEvent) {
if (event.deltaY < 0) {
this.zoomIn();
} else if (event.deltaY > 0) {
this.zoomOut();
}
}
source: https://github.com/Microsoft/TypeScript/issues/9071

Unity - Why iPhone 6 and 7 behaves differently to touch input?

I have below code in Update() to drag camera and also detect clicks on objects. When we try on iphone 6 and X it works all well, but when we try on iPhone7 the drag screen is very unresponsive and clicking objects works only when you touch the screen very very lightly. Anybody have an idea on what is going on?
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) {
fingerMoved = false;
if (_eventSystem.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) {
fingerMoved = true;
}
hit_position = Input.GetTouch(0).position;
camera_position = cam.position;
} else if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
current_position = Input.GetTouch(0).position;
LeftMouseDrag();
if (Vector2.Distance(hit_position, current_position) > 7f) {
fingerMoved = true;
}
cam.DOMoveY(target_position.y, 0.75f);
} else if (!fingerMoved && Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended) {
foreach (var item in storageList) {
if (Vector2.Distance(item.transform.position, Camera.main.ScreenToWorldPoint(hit_position)) < 0.5f) {
sideMenu.Open(item.myNo);
}
}
}
void LeftMouseDrag() {
Vector3 direction = Camera.main.ScreenToWorldPoint(current_position) - Camera.main.ScreenToWorldPoint(hit_position);
direction.x = 0f;
direction = direction * -1;
target_position = camera_position + direction;
if (target_position.y > camMaxY) {
target_position.y = camMaxY;
}
if (target_position.y < camMinY) {
target_position.y = camMinY;
}
}
I am unsure if it makes a difference but for this kind of stuff its easier and more reliable to use EventSystems and OnPointerClick / OnPointerDrag hanlders. This way, at least in theory, any sensitivity differences could be leveled out by Unity itself. (I am not aware weather it does it or not its just
The problem has gone by itself, I have no idea what went wrong at first.
I was having the same problem and fixed it by adding the second line of the code displayed below.
else if (Input.GetTouch(0).phase == TouchPhase.Moved)
if (master.calcDelta(Input.GetTouch(0).position) > 0f)
Which in turn, calculates the length of the vector that represents the dislocation from the previous location to the actual one.
calculatedDelta = Mathf.Abs(_touchPos.magnitude - pastPos.magnitude);
What is does is prevents the jittering from interfering with the built in function from unity "TouchPhase.Moved".

Java compiling wrong old file

I have a java app that runs an infinite while loop. When I click run on eclipse it seems to be reverting to old code that I have changed. The thing is, when I build it updates at random times. The latest time I added System.exit(). I changed the code and it still exits. I have also tried this program in C#. I feel that I am somehow confusing the language runtime with the infinite while loop. The program works on a series of changing boolean values. The main action I am looking at the erratic behavior (this was what was happening before I added System.exit()) is in a method that iterates pixels in a BufferedImage. I am running Ubuntu 14.10. I have tried making a new project and pasting the same code (could it be invisible chars somehow?) I am very confused and would be happy if someone could help.
while(true){
if (bool1 && !exe.isSeparate(image))
{
// change boolean values
// did run System.exit(0)
}
if (bool2 && !exe.isSeparate(image))
{
// change boolean values
// did run System.exit(0)
}
}
boolean isSeparate(BufferedImage image)
{
int x = touchingX;
boolean first = false, second = false, third = false;
int startAt = this.getYStart(image);
for (int y = startAt; y < startAt + 150; y++)
{
Color pixel = new Color(image.getRGB(x, y));
if (!(pixel.getRed() == 255 && pixel.getGreen() == 255 && pixel.getBlue() == 255)
&& !(pixel.getRed() == 0 && pixel.getGreen() == 68 && pixel.getBlue() == 125))
{
if (!first)
{
first = true;
}
if (first && second && !third)
{
third = true;
}
}
else
{
if (first && !second)
{
second = true;
}
}
}
if (first && second && third)
{
return true;
}
return false;
}
I have answered my question. Ironically, it was a logic error.

Sencha Touch 2.3.1 list scroll freezing

I'm using Sencha Touch 2.3.1 and using a list defined like this :
{
xtype: 'list',
id: 'index_list',
infinite: true,
flex: 1,
scrollToTopOnRefresh: false,
disableSelection: true,
store: 'store_index'
}
List's store has got more than 300 records, that's why I put the flag "infinite" to true.
Problem is when I scroll very fastly up and down through the list, app freezes and I can't do anything else with UI.
Also tested, put infinite flag to false doesn't fix it.
Cannot reproduce if data are less than ~300 records.
Platforms : iOS 6, 7 (iPhone), not iPad.
Have you got any idea ?
Use this override works for me
Ext.define('InfiniteListScroll.override.TouchGesture', {
override: 'Ext.event.publisher.TouchGesture',
lastEventType: null,
changedTouchesId: null,
lastEventObject: null,
onEvent: function(e) {
console.log('InfiniteListScroll.override.TouchGesture - onEvent');
var type = e.type,
lastEventType = this.lastEventType,
touchList = [e];
if ( type == 'touchstart' ) {
if( this.changedTouchesId == null ) {
this.changedTouchesId = e.changedTouches[0].identifier;
this.lastEventObject = e;
}
else {
console.log('changedTouchesId NOT null, touchEnd event wasnt fired for corresponding touchStart event.');
this.onTouchEnd( this.lastEventObject );
}
}
if (this.eventProcessors[type]) {
this.eventProcessors[type].call(this, e);
return;
}
if ('button' in e && e.button > 0) {
return;
}
else {
// Temporary fix for a recent Chrome bugs where events don't seem to bubble up to document
// when the element is being animated with webkit-transition (2 mousedowns without any mouseup)
if (type === 'mousedown' && lastEventType && lastEventType !== 'mouseup') {
var fixedEvent = document.createEvent("MouseEvent");
fixedEvent.initMouseEvent('mouseup', e.bubbles, e.cancelable,
document.defaultView, e.detail, e.screenX, e.screenY, e.clientX,
e.clientY, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, e.metaKey,
e.button, e.relatedTarget);
this.onEvent(fixedEvent);
}
if (type !== 'mousemove') {
this.lastEventType = type;
}
e.identifier = 1;
e.touches = (type !== 'mouseup') ? touchList : [];
e.targetTouches = (type !== 'mouseup') ? touchList : [];
e.changedTouches = touchList;
this.eventProcessors[this.mouseToTouchMap[type]].call(this, e);
}
},
onTouchEnd: function(e) {
console.log('InfiniteListScroll.override.TouchGesture - onTouchEnd');
if (!this.isStarted) {
return;
}
if (this.lastMoveEvent) {
this.onAnimationFrame();
}
var touchesMap = this.touchesMap,
currentIdentifiers = this.currentIdentifiers,
changedTouches = e.changedTouches,
ln = changedTouches.length,
identifier, i, touch;
this.changedTouchesId = null;
this.updateTouches(changedTouches);
changedTouches = e.changedTouches;
for (i = 0; i < ln; i++) {
Ext.Array.remove(currentIdentifiers, changedTouches[i].identifier);
}
e = this.factoryEvent(e);
for (i = 0; i < ln; i++) {
identifier = changedTouches[i].identifier;
touch = touchesMap[identifier];
delete touchesMap[identifier];
this.publish('touchend', touch.targets, e, {touch: touch});
}
this.invokeRecognizers('onTouchEnd', e);
// Only one touch currently active, and we're ending that one. So currentTouches should be 0 and clear the touchMap.
// This resolves an issue in iOS where it can sometimes not report a touchend/touchcancel
if (e.touches.length === 1 && currentIdentifiers.length) {
currentIdentifiers.length = 0;
this.touchesMap = {};
}
if (currentIdentifiers.length === 0) {
this.isStarted = false;
this.invokeRecognizers('onEnd', e);
if (this.animationQueued) {
this.animationQueued = false;
Ext.AnimationQueue.stop('onAnimationFrame', this);
}
}
}
});

Cannot capture TouchEvent.UP in Blackberry

I am working on a Scrollable Image field.I am handling TouchEvent.DOWN mTouchEvent.MOVE,TouchEvent.UP.
Somehow control never goes to TouchEvent.UP section.How to capture the UP event.
I have to findout the start and end points of the drag.
My Code looks like this..
if (event == TouchEvent.DOWN && touchEvent.isValid())
{
_xTouch = touchEvent.getX(1);
_yTouch = touchEvent.getY(1);
}
else if(event == TouchEvent.UP && touchEvent.isValid())
{
int x = touchEvent.getX(1);
int y = touchEvent.getY(1);
}
else if (event == TouchEvent.MOVE && touchEvent.isValid())
{
boolean result = scrollImage((touchEvent.getX(1) - _xTouch), (touchEvent.getY(1) - _yTouch));
_xTouch = touchEvent.getX(1);
_yTouch = touchEvent.getY(1);
//If scrolling occurred, consume the touch event.
if (result)
{
return true;
}
else
{
return false;
}
}
Thanks in advance.
:)
it was a misunderstanding.I was handling the touch event in multiple layers..like Field level,layout manager level and screen level.
So in particular case..it was being cosumed by manager.And i need the event to be cosumed by field.
It was a mistake in return value.

Resources